- Ansible Playbook Cheat Sheet Pdf
- Ansible Playbook Cheat Sheet Example
- Ansible Playbook Cheat Sheet 2020
Linux
- Ansible modules are standalone scripts that can be used inside an Ansible playbook. You can use these modules to run whatever commands it needs to get its job done. Ansible modules are categorized into various groups based on their functionality. There are hundreds of Ansible modules are available.
- To know more about Ad hoc commands and how to use them please refer to the following Cheat Sheet. Ansible AD HOC commands Cheatsheet. A Quick Syntax of Ansible Shell module in a Playbook. The Beauty of Playbook is the way it looks and written. Since it is written in yaml it can be easily understood as well.
- Ansible Cheat Sheet Ansible is an open source Continuous Deployment, Configuration Management, & Orchestration. This tool aims to provide large productivity gains to a wide variety of automation challenges and is powerful enough to automate complex multi-tier IT application environments.
Packages:
- git
- python
- python-devel
- python-pip
- openssl
- ansible
Linux
Be sure to install epel-release first and then update your caches (if CentOS). On Ubuntu/Debian distributions, you may install from the default repositories. Assuming CentOS, as in our course, do the following:
Running a playbook¶ ansible-playbook playbook options ansible-playbook playbook.yml –start-at=”install packages” The above will start executing your playbook at a task named “install packages”. Ansible-playbook playbook.yml –step. This will cause ansible to stop on each task, and ask if it should execute that task.
sudo yum install git python python-devel python-pip openssl ansible
User Accounts
Create a user called ansible (example) on the server you intend to use Ansible to run playbooks from AND each of the Ansible nodes you intend to run playbooks on. Set the user as a sudo-capable user and include the NOPASSWD: ALLdirective in /etc/sudoers.
Create an SSH key with ssh-keygen on the Ansible server. Exchange that key using ssh-copy-id on each of the nodes you are running playbooks on. This allows the playbook to run with escalated privileges as needed.
Configuration Files
- /etc/ansible/ansible.cfg
- Primary Ansible configuration file (agentless, daemon-less configuration, read on each ansible command run)
- Uncomment “inventory” field
- Uncomment “become user” field
- /etc/ansible/hosts
- Copy original to /etc/ansible/hosts.original
- Create one or more sections with group names, sample below
ansible GROUPNAME-a'ls -al /home/ansible'
Running a command that requires sudo privileges should not be run with the sudo command, but rather the sudo parameter in the ansible command itself, like so:ansible GROUPNAME -s -a “ls -al /var/log/messages”
ansible GROUPNAME-s-a'ls -al /var/log/messages'
You can also execute a single module against one or more hosts at the command line by using the module parameter. As an example:ansible GROUPNAME -s -m yum -a “name=httpd state=latest”
ansible GROUPNAME-s-myum-a'name=httpd state=latest'
Test if all machines in your inventory respond to a ping request:
ansible all-mping
YAML Structure for Playbooks