Ansible Notes
Ansible Notes

Ansible Notes

Tags
DevOps
Ansible
Published
August 7, 2021
💡
The old content of this page has been remove and will be updated with new one

Ansible

ℹ️
Manage groups of computers remotely over SSH. (use the /etc/ansible/hosts file to add new groups/hosts). Some subcommands such as ansible galaxy have their own usage documentation. More information: https://www.ansible.com/.
  • List hosts belonging to a group:
ansible {{group}} --list-hosts
  • Ping a group of hosts by invoking the ping module:
ansible {{group}} -m ping
  • Display facts about a group of hosts by invoking the setup module:
ansible {{group}} -m setup
  • Execute a command on a group of hosts by invoking command module with arguments:
ansible {{group}} -m command -a '{{my_command}}'
  • Execute a command with administrative privileges:
ansible {{group}} --become --ask-become-pass -m command -a '{{my_command}}'
  • Execute a command using a custom inventory file:
ansible {{group}} -i {{inventory_file}} -m command -a '{{my_command}}'
  • List the groups in an inventory:
ansible localhost -m debug -a '{{var=groups.keys()}}'

ansible.cfg

ℹ️
Used to store defaults values for ansible. It can be either in /etc/ansible or locally. Local files overwrites the /etc/ansible file.

inventory

Ansible inventory is a collection of hosts and their associated variables. It can be either in a YAML or INI format. Inventory files can be used to define variables for each host, create groups of hosts, and assign variables to those groups. Additionally, inventory can be dynamically generated by scripts, cloud providers, and other external sources.

.yaml files

Flags Commands

-m or module

--become --ask-become-pass or sudo access