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

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.
主站蜘蛛池模板: 惠州市| 手机| 双牌县| 西藏| 潼关县| 比如县| 渝中区| 渝北区| 天台县| 行唐县| 大关县| 通化市| 五原县| 三亚市| 绥化市| 多伦县| 平舆县| 镇巴县| 灯塔市| 白河县| 汉中市| 娱乐| 依安县| 双柏县| 栾城县| 罗定市| 新田县| 兴义市| 宣武区| 江山市| 阳朔县| 都匀市| 靖边县| 叙永县| 个旧市| 光山县| 阳新县| 茌平县| 遂平县| 宁化县| 铁岭县|