Ansible

Ansible Cheatsheet #

Ansible is an open-source automation tool used for IT tasks such as configuration management, application deployment, and orchestration. It uses a simple, human-readable language (YAML) to describe automation jobs, which allows IT administrators to manage systems without needing to understand complex programming languages.

Ansible Basics #

Command/OptionExampleDescription
ansible –versionansible --versionDisplay the version of Ansible installed
ansible -m pingansible all -m pingPing all hosts in the inventory to check connectivity

Inventory Management #

Command/OptionExampleDescription
ansible-inventory –listansible-inventory --listList all hosts in the inventory
ansible-inventory –graphansible-inventory --graphDisplay inventory as a graph

Running Ad-hoc Commands #

Command/OptionExampleDescription
ansible -m -aansible webservers -m yum -a "name=httpd state=present"Run a module with arguments on a host or group of hosts
ansible webservers -a “/usr/bin/uptime”ansible webservers -a "/usr/bin/uptime"Run a command on a group of hosts

Playbook Management #

Command/OptionExampleDescription
ansible-playbook <playbook.yml>ansible-playbook site.ymlRun a playbook
ansible-playbook <playbook.yml> –checkansible-playbook site.yml --checkPerform a dry run of a playbook
ansible-playbook <playbook.yml> –diffansible-playbook site.yml --diffShow differences between current and configured states

Roles and Galaxy #

Command/OptionExampleDescription
ansible-galaxy installansible-galaxy install username.role_nameInstall a role from Ansible Galaxy
ansible-galaxy listansible-galaxy listList installed roles
ansible-galaxy init <role_name>ansible-galaxy init my_roleCreate a new role skeleton

Vault #

Command/OptionExampleDescription
ansible-vault createansible-vault create secrets.ymlCreate a new encrypted file
ansible-vault editansible-vault edit secrets.ymlEdit an encrypted file
ansible-vault viewansible-vault view secrets.ymlView an encrypted file
ansible-vault encryptansible-vault encrypt secrets.ymlEncrypt a file
ansible-vault decryptansible-vault decrypt secrets.ymlDecrypt a file

Configuration Management #

Command/OptionExampleDescription
ansible-config listansible-config listList all configuration options
ansible-config dumpansible-config dumpDisplay the current configuration

Inventory and Hosts #

Command/OptionExampleDescription
ansible -m setupansible all -m setupGather facts about remote hosts
ansible-playbook -i <playbook.yml>ansible-playbook -i inventory.ini site.ymlRun a playbook with a specified inventory file

Miscellaneous #

Command/OptionExampleDescription
ansible-docansible-doc yumShow documentation for a module
ansible-pull -Uansible-pull -U https://github.com/user/repo.gitPull and apply a playbook from a VCS repository

This cheatsheet covers the most commonly used Ansible commands and options, helping you to manage inventories, run ad-hoc commands, execute playbooks, manage roles and vaults, and configure settings effectively.

Ansible

Explore our comprehensive cheatsheets to enhance your knowledge and efficiency. Each cheatsheet provides detailed command options, examples, and descriptions to help you master various tools and technologies.