官术网_书友最值得收藏!

  • Learning DevOps
  • Mikael Krief
  • 276字
  • 2021-06-24 12:32:01

Declarative types

These are languages in which it is sufficient to write the state of the desired system or infrastructure in the form of configuration and properties. This is the case, for example, for Terraform and Vagrant from HashiCorp, Ansible, the Azure ARM template, PowerShell DSC, Puppet, and ChefThe user only has to write the final state of the desired infrastructure and the tool takes care of applying it.

For example, the following is the Terraform code that allows you to define the desired configuration of an Azure resource group:

resource "azurerm_resource_group" "myrg" {
name = "MyAppResourceGroup"
location = "West Europe"

tags = {
environment = "Bookdemo"
}
}

In this example, if you want to add or modify a tag, just modify the tags property in the preceding code and Terraform will do the update itself.

Here is another example that allows you to install and restart nginx on a server using Ansible:

---
- hosts: all
tasks:
- name: install and check nginx latest version
apt: name=nginx state=latest
- name: start nginx
service:
name: nginx
state: started

And to ensure that the service is not installed, just change the preceding code, with service as an absent value and the state property with the stopped value:

---
- hosts: all
tasks:
- name: stop nginx
service:
name: nginx
state: stopped
- name: check nginx is not installed
apt: name=nginx state=absent

In this example, it was enough to change the state property to indicate the desired state of the service.

For details regarding the use of Terraform and Ansible, see  Chapter 2, Provisioning Cloud Infrastructure with Terraform, and Chapter 3, Using Ansible for Configuring IaaS Infrastructure.
主站蜘蛛池模板: 古丈县| 秀山| 巴塘县| 漳州市| 太湖县| 邳州市| 马鞍山市| 鞍山市| 诏安县| 阳曲县| 淮北市| 嫩江县| 安西县| 凤山县| 莱西市| 香河县| 隆昌县| 安义县| 拉萨市| 原阳县| 麦盖提县| 通许县| 海淀区| 沅陵县| 九龙城区| 黎平县| 吉林省| 牟定县| 三穗县| 定边县| 财经| 济阳县| 贵定县| 剑川县| 昭通市| 衡水市| 曲阳县| 绥滨县| 靖安县| 兴安县| 资源县|