Terminologia¶
Inventory¶
Plik z opisem hostów oraz grup.
Formaty: - INI
mail.example.com
[webservers]
foo.example.com
34.13.15.257
[dbservers]
one.example.com
two.example.com
34.13.15.257
- YAML
all:
hosts:
mail.example.com:
children:
webservers:
hosts:
foo.example.com:
34.13.15.257"
dbservers:
hosts:
one.example.com:
two.example.com:
34.13.15.257:
- PY (Dynamic inventory)
#!/usr/bin/env python
import json
import boto3
def main():
ec2 = boto3.resource('ec2')
filters = [
{
'Name': 'instance-state-name',
'Values': ['running']
}
]
instances = ec2.instances.filter(Filters=filters)
hosts = []
for instance in instances:
hosts.append(instance.public_ip_address)
inventory = {'aws': {
'hosts': hosts,
'vars': {
'ansible_ssh_private_key_file': 'pycon-key.pem',
'ansible_user': 'ubuntu'
}
}}
print json.dumps(inventory)
if __name__ == "__main__":
main()
Task¶
Pojedyncze zadania wykonywane na zdalnej maszynie
- name: install python3-sphinx
apt:
name: python3-sphinx
state: present
Playbook¶
Orkiestracja zadań, konfiguracji oraz deploymentu.
- hosts: all
tasks:
- name: ensure nginx is at the latest version
apt:
name: nginx
state: latest
- name: start nginx
service:
name: nginx
state: started
Note
They are called playbooks partially because it’s a sports analogy, and it’s supposed to be fun using them. They aren’t workbooks :)`doc`_
Role¶
Jednostka z zadaniami, konfiguracją, zmiennymi itp.
roles/
common/
tasks/
handlers/
files/
templates/
vars/
defaults/
meta/