- automation engine for provisioning, configuration management, application deployment orchestration and more
-
basic workflow:
- connects to machines (inventory)
- push module
- run tasks in module
- remove module upon completion
- does not require additional software on nodes
- uses ssh for communication with nodes
- root login is not required
- configuration uses YAML format
- aware of the state of the machine
- if the state does not match the desired state it will execute the necessary steps to get there
- can run in "check mode" to see what would be executed
- machines to run tasks on are tracked in an inventory
- standalone programs
- can be written in different languages
- must return json
- builtin modules
- documentation
- group machines
-
predefined groups are
all
(containing all machines) andungrouped
(not belonging to any group exceptall
) - same machine can appear under different groups (multiple groups per machine)
- can define variables for every group (actual value determined by precedence described later on)
-
example inventory YAML:
--- all: children: <group name>: hosts: <an ip address or hostname> vars: <some variable>: <some value>
-
ansible <target> -m <module> [other options]
- run single module on target (default is 'command')
- target can be a group or individual hostname/ip
-
notable opions:
-
-u <user>
-
-a <additional arguments for the module>
(e.g. shell commands to execute when using command module) -
-i <non-default inventory file>
-
- YAML file
- available keywords
- can be checked by linter
-
ansible-playbook <playbook file> [other options]
-
contain one or more plays:
- define the desired state of the system
-
contain ordered set of tasks:
- executed in the order they are written
- call modules
-
can trigger handler:
- specific task only after a certain change
- run once after all other plays in the playbook
-
can contain variables:
- alter execution of the playbook
- used to account for differences between systems
-
follow precedence for overwriting (from highest to lowest, src):
-
extra vars (
-e "<var>=<value>"
) - include params
- role params
- set_facts / registered vars
- include_vars
- task vars
- block vars
- role vars
- play vars_files
- play vars_prompt
- play vars
- host facts
- playbook host_vars/
- inventory host_vars/
- inventory file
- playbook group_vars/
- inventory group_vars/
- playbook group_vars/all
- inventory group_vars/all
- inventory file
- role defaults (role/defaults/main.yml)
- command line values
-
extra vars (
- playbook that is fully self-contained
- contains all tasks, variables, config templates and other supporting files that are needed
- distribution format for ansible content
- can include playbooks, roles, modules and plugins
(from highest to lowest, src)
-
extra variables (
-e
) - variables (see variable precedence)
-
playbook keywords:
- tasks
- blocks, includes, roles
- play
- command line options
-
configuration settings:
- environment variables
- default config