๐ด Ansible Dictionary
Every keyword, operator, and symbol โ with plain-English explanations.
PLAYBOOK DIRECTIVES AnsiblePlaybook directives define the structure and control flow of an Ansible playbook.
- hosts: all\n- gather_facts: no\n- tasks:\n - name: Example task\n debug: msg: "Hello, world!"
TASK DIRECTIVES AnsibleTask directives control the behavior of individual tasks within a playbook.
- name: Example task\n shell: echo "Hello, world!"
FILE MODULES AnsibleFile modules handle file-related tasks such as copying, templating, and managing files and directories.
- copy: src=/path/to/file dest=/path/to/destination
COMMAND MODULES AnsibleCommand modules execute shell commands and scripts on remote hosts.
- command: ls -l
PACKAGE MODULES AnsiblePackage modules manage software packages on remote hosts.
- apt: name=httpd state=present
SERVICE MODULES AnsibleService modules manage services and their states on remote hosts.
- service: name=apache2 state=started
USER MODULES AnsibleUser modules manage user accounts and groups on remote hosts.
- user: name=example_user state=present
NETWORK MODULES AnsibleNetwork modules manage network-related tasks such as configuring firewalls and managing network services.
- ufw: state=present rule=add
FIREWALL MODULES AnsibleFirewall modules manage firewall configurations on remote hosts.
- ufw: state=present rule=add
VARIABLE USAGE AnsibleVariable usage involves setting, registering, and using variables within a playbook.
- set_fact: my_variable={{ 'value' }}JINJA2 FILTERS AnsibleJinja2 filters modify variables in a playbook using Jinja2 templating language filters.
- set_fact: my_variable={{ 'value' | lower }}CONDITIONALS AnsibleConditional statements allow for conditional execution of tasks based on certain conditions.
- when: ansible_os_family == 'RedHat'
ANSIBLE-PLAYBOOK FLAGS AnsiblePlaybook flags are options used to control the execution of an Ansible playbook.
--check
hostvars Ansiblehostvars is a variable in Ansible that provides access to the facts and data of a specific host in the inventory.
- debug: msg="{{ hostvars['example_host'] }}"inventory_hostname Ansibleinventory_hostname is a variable in Ansible that represents the hostname of the current host in the inventory.
- debug: msg="{{ inventory_hostname }}"ansible_host Ansibleansible_host is a variable in Ansible that represents the IP address or hostname of the remote host to connect to.
- debug: msg="{{ ansible_host }}"ansible_port Ansibleansible_port is a variable in Ansible that represents the port number to connect to the remote host.
- debug: msg="{{ ansible_port }}"ansible_user Ansibleansible_user is a variable in Ansible that represents the username to use for connecting to the remote host.
- debug: msg="{{ ansible_user }}"ansible_password Ansibleansible_password is a variable in Ansible that represents the password to use for connecting to the remote host.
- debug: msg="{{ ansible_password }}"ansible_ssh_private_key_file Ansibleansible_ssh_private_key_file is a variable in Ansible that represents the path to the SSH private key file to use for connecting to the remote host.
- debug: msg="{{ ansible_ssh_private_key_file }}"ansible_become Ansibleansible_become is a variable in Ansible that controls whether the task should be run with sudo or become privileges.
- debug: msg="{{ ansible_become }}"ansible_become_user Ansibleansible_become_user is a variable in Ansible that represents the user to become when running a task with become privileges.
- debug: msg="{{ ansible_become_user }}"ansible_python_interpreter Ansibleansible_python_interpreter is a variable in Ansible that represents the Python interpreter to use on the remote host.
- debug: msg="{{ ansible_python_interpreter }}"ansible_connection Ansibleansible_connection is a variable in Ansible that represents the connection type to use for connecting to the remote host.
- debug: msg="{{ ansible_connection }}"vars Ansiblevars is a variable in Ansible that represents a dictionary of variables to be used in the playbook.
- vars:\n my_var: value
vars_files Ansiblevars_files is a variable in Ansible that represents a list of files containing variables to be loaded into the playbook.
- vars_files:\n - /path/to/vars1.yaml\n - /path/to/vars2.yaml
vars_prompt Ansiblevars_prompt is a variable in Ansible that represents a list of variables to be prompted for when the playbook is run.
- vars_prompt:\n - name: my_var\n prompt: What is your value?
tasks Ansibletasks is a keyword in Ansible that represents a list of tasks to be executed in a playbook.
- tasks:\n - name: Example task\n debug: msg: "Hello, world!"
handlers Ansiblehandlers are tasks that are triggered by specific events or conditions in a playbook.
- handlers:\n - name: Restart service\n service: name=apache2 state=restarted
pre_tasks Ansiblepre_tasks are tasks that are executed before the main tasks in a playbook.
- pre_tasks:\n - name: Create directory\n file: path=/var/www/html state=directory
post_tasks Ansiblepost_tasks are tasks that are executed after the main tasks in a playbook.
- post_tasks:\n - name: Cleanup\n file: path=/var/www/html state=absent
any_errors_fatal Ansibleany_errors_fatal is a flag in Ansible that controls whether an error in a task should cause the playbook to fail.
- any_errors_fatal: true
ignore_errors Ansibleignore_errors is a flag in Ansible that controls whether errors in a task should be ignored and the playbook should continue execution.
- ignore_errors: true
max_fail_percentage Ansiblemax_fail_percentage is a flag in Ansible that controls the maximum percentage of tasks that can fail before the playbook fails.
- max_fail_percentage: 50
run_once Ansiblerun_once is a flag in Ansible that controls whether a task should be executed only once during the entire playbook run.
- run_once: true
serial Ansibleserial is a keyword in Ansible that controls the number of tasks that should be executed in parallel during the playbook run.
- serial: 1