Ansible Playbook Options
Let's explore the various options available when running an Ansible playbook using the ansible-playbook
command.
--version
:Displays the Ansible version information.
Example:
ansible-playbook --version
--syntax-check
:Validates the syntax of your playbook without executing it.
Useful for catching syntax errors before running the playbook.
Example:
ansible-playbook myplaybook.yml --syntax-check
-C
or--check
:Performs a dry run (check mode) without making any changes.
Simulates playbook execution and reports what changes would occur.
Useful for testing before applying changes in production.
Example:
ansible-playbook myplaybook.yml --check
-i
or--inventory
or--inventory-file
:Specifies the inventory file (hosts file) to use.
By default, Ansible looks for the inventory file at
/etc/ansible/hosts
.Example:
ansible-playbook -i my_inventory.ini myplaybook.yml
--list-hosts
:Outputs a list of matching hosts from the inventory.
Does not execute any tasks; useful for host discovery.
Example:
ansible-playbook myplaybook.yml --list-hosts
--list-tasks
:Lists all tasks defined in the playbook.
Useful for understanding the playbook structure.
Example:
ansible-playbook myplaybook.yml --list-tasks
--list-tags
:Lists all available tags defined in the playbook.
Helps identify which tasks are associated with specific tags.
Example:
ansible-playbook myplaybook.yml --list-tags
-f <FORKS>
or--forks <FORKS>
:Sets the number of parallel processes (concurrent connections).
Controls how many hosts Ansible manages simultaneously.
Example:
ansible-playbook -f 10 myplaybook.yml
-T <TIMEOUT>
or--timeout <TIMEOUT>
:Sets the SSH connection timeout (in seconds).
Useful for adjusting the connection timeout threshold.
Example:
ansible-playbook -T 30 myplaybook.yml
-k
or--ask-pass
:Prompts for the SSH password (deprecated; use SSH keys instead).
Example:
ansible-playbook -k myplaybook.yml
-K
or--ask-become-pass
:Prompts for the privilege escalation (become) password.
Useful when using
--become
(sudo) for privilege escalation.Example:
ansible-playbook -K myplaybook.yml
-u <REMOTE_USER>
or--user <REMOTE_USER>
:Specifies the remote user for SSH connections.
Example:
ansible-playbook -u myuser myplaybook.yml
-b
or--become
:Enables privilege escalation (become) for tasks.
Equivalent to using
sudo
orsu
.Example:
ansible-playbook -b myplaybook.yml
--become-user <BECOME_USER>
:Specifies the user for privilege escalation (become).
Useful when becoming a different user (e.g., root).
Example:
ansible-playbook --become-user root myplaybook.yml
--step
:Executes tasks interactively, prompting for confirmation.
Useful for debugging and understanding task execution.
Example:
ansible-playbook --step myplaybook.yml
-l <SUBSET>
or--limit <SUBSET>
:Limits execution to specific hosts or groups.
Useful for targeting specific subsets of hosts.
Example:
ansible-playbook -l web_servers myplaybook.yml
--skip-tags
:Excludes specific tags during playbook execution.
Example:
ansible-playbook --skip-tags packages myplay
-e
or--extra-vars
: This option allows you to pass extra variables to your playbook. You can use it to override variables defined in your playbook or provide additional input during execution. For example:
ansible-playbook myplaybook.yml -e "my_variable=value"
-h
or--help
: Use this option to display the help message, which provides information about the available options and their usage. It's always a good idea to check the help documentation when you're unsure about a specific command. 😊-t
or--tags
: Tags allow you to selectively run specific tasks or roles within your playbook. You can assign tags to tasks in your playbook, and then use this option to execute only the tagged tasks. For example:
ansible-playbook myplaybook.yml -t my_tag
Reference
Ansible Playbook Options - If you’d like more details or need additional options
Last updated