01
Primeiros passos
Inventory
O inventory define os hosts de destino.
ansible
# inventory.ini
[webservers]
web1 ansible_host=192.168.1.10
web2 ansible_host=192.168.1.11
[databases]
db1 ansible_host=192.168.1.20Playbook
Playbooks definem tarefas de automação em YAML.
ansible
---
- hosts: webservers
tasks:
- name: Install nginx
apt: name=nginx state=present
- name: Start nginx
service: name=nginx state=startedComandos
Comandos ad-hoc e execução de playbooks.
ansible
# ansible all -m ping
# ansible-playbook site.yml
# ansible-playbook -l webservers site.yml02
Recursos
Variáveis
Variáveis e templates Jinja2.
ansible
vars:
http_port: 80
max_clients: 200
tasks:
- name: Template config
template: src=nginx.conf.j2 dest=/etc/nginx/nginx.confRoles
Roles para unidades de automação reutilizáveis.
ansible
# ansible-galaxy init myrole
# structure:
# myrole/tasks/main.yml
# myrole/vars/main.yml
# myrole/templates/Condicionais
Condicionais when para execução de tarefas.
ansible
tasks:
- name: Install on Debian
apt: name=nginx
when: ansible_os_family == "Debian"Was this helpful?