Ansible Cheatsheet

Ping machine

ansible -i ./inventory/hosts <group_name> -m <command> --user <server_user> --ask-pass

Password prompt with apk-pass

ansible -i ~/ansible/inventory servers -m ping --user root --ask-pass

Playbook run:

playbooks are used to automate tasks

To run playbook:

ansible-playbook ~/ansible/playbooks/<playbook_name> --user <server_user> --ask-pass --ask-become-pass -i ~/ansible/inventory

--ask-become-pass asks to become super user

To run playbook and become super user:

To run playbook with specific key use args: --key-file

To run playbook for ssh autorized_keys:

To check playbook syntax use:

To check the playbook tags use:

ansible-playbook <path-to-playbook/playbook.yml> --list-tags

To execute playbook with tags use:

To execute multiple tags:

To execute playbook for specific groups, you have to provide the hosts file like so:

The playbook must include the group required to run this:

To roll out specific hosts file with specific user and user password run:

Last updated