Ansible Cheatsheet - BETA: Still draft
Ansible Ad-Hoc Comamands
Simple Ad-Hoc Command |
|
Specify specfic host, note |
|
Specify inventory file |
|
Pass arguments to module |
|
Common options
-
-m
module name, e.g.yum
-
-i
inventory source-
-i hosts
read inventory from filehosts
-
-i inventory/ec2.py
execute dynamic inventory script
-
Ansible Playbook Comamands
Simple A`ansible-playbook` Command |
|
Simple A`ansible-playbook` Command |
|
|
Specify inventory file |
|
Pass arguments to module |
ansible.cfg
files
-
Precedence
Sample
ansible.cfg
with callbacks enabled[defaults] inventory = inventory stdout_callback = default bin_ansible_callbacks = True callback_whitelist = yaml, timer, profile_tasks [ssh_connection] ssh_args = -F ./ssh.cfg (1)
-
All ssh configuration encapsulated in
ssh.cfg
file
-
Inventory
ansible-inventory --graph --vars -i my-inventory
ansible-inventory --host appdb1.da4a.internal --vars -i fix-inventory
In-Memory Inventory Examples
A common pattern in cloud, VM, or Container creation is to create the objects
(e.g. using say ec2
module) then
-
Get instance facts
-
Call add-host with instance facts register
name: Fetch Instance Info (1) os_server_facts: cloud: ospcloud region_name: RegionOne register: result - name: Add host (2) add_host: name: "{{ item.public_v4 }}" group: "{{ item.metadata.group }}" loop: "{{ result.ansible_facts.openstack_servers }}"