Ansible Cheat Sheet
Ansible Cheat Sheet
Ansible Cheat Sheet
Copy your Ansible Master's public key to the managed install Role (Module)
node ansible-galaxy install
ssh-keygen ## generate public key geerlingguy.nginx
ssh-copy-id <name of node> # copy key,
provide password to node
Ping specific node run playbook but only a specific task (tag)
ansible -i hosts nycweb01.prod.local -m ansible-playbook
ping playbooks/restore_bitbucket.yaml -
i hosts --tags rsync
Ping with wildcard
ansible -i hosts "nycweb*" -m ping
or to skip: (--skip-tags tag1,
tag2)
Ping all nodes with SSH user 'root'
ansible -i hosts all -m ping -u root
store output of a command as a variable
shell: cat /etc/network | grep
run a command eth0
ansible -i hosts dev -a 'uname -a'
register: address
debug: msg="address is {{
check Yum packages address.stdout }}"
ansible -i hosts dev -m yum
check if Docker rpm is installed configure multiple items with one task
ansible -i hosts web01.nyc.local -m
shell -a "rpm -qa | grep docker"
- name: more complex items to add
several users
Get facts about a box user:
ansible -i hosts web01.nyc.local -m name: "{{ item.name }}"
setup -a 'filter=facter_*' uid: "{{ item.uid }}"
groups: "{{ item.groups }}"
run command with sudo state: present
ansible -i hosts target-host -m shell -a with_items:
"cat /etc/sudoers" --sudo - { name: testuser1, uid:
1002, groups: "wheel, staff" }
limit command to a certain group or server: add -- - { name: testuser2, uid:
limit *.nyc 1003, groups: staff }
Debug (debug output for playbook) run playbook on multiple Host groups
- debug: var=result verbosity=2 - hosts: "search_head, deployer"
hosts: 127.0.0.1
PACKAGES AND INSTALLATION connection: local
>> https://10.123,1.0:8089,
copy public ssh key to remote
https://10.123.1.1:8089, etc etc
authorized_keys file
[fruits]
sweet=banana, apple, grapes
bitter=grapefruit