Ansible is a tool used for configuration management. In this context, configuration management entails keeping a record of company hardware and software, and making changes to them remotely.
Ansible Playbooks are the files where Ansible code is written. These files are written in the language, YAML, which is a funny acronym for, “YAML Ain’t no Markup Language.”
Playbooks contain one or more Plays. Plays map a group of computers to a few well-defined roles known as Tasks. Tasks can be defined as Ansible scripts.
YAML is a simple language that consists of key-value pairs. While not mandatory, ---
marks the beginning of a YAML program, and ...
marks the end.
---john: #variable declared here#data defined in following lines:name: john doeaddress: new york citygender: male...
The previous example defines the name, address, and gender of a fictionary person (John Doe) in the john
variable.
YAML also allows the creation of lists. Lists can be created with the -
symbol inside variables to define elements.
The following example defines a list of cities with their full name and state.
---cities: #list declaration- newYorkCity: #list element declared here#element data defined here:name: new york citystate: new york- losAngeles: #list element declared here#element data defined here:name: los angelesstate: california- philadelphia: #list element declared here#element data defined here:name: philadelphiastate: pennsylvania...
For every play, a number of hosts and remote users are defined.
The hosts
are a list of machines. The remote_user
is the name of the user for which the play is being defined.
The tasks for a play are defined in the tasks
key.
---- hosts: allremote_user: roottasks:- name: copy filewin_copy:src: C:\source.txtdest: C:\destination\remote_src: yes...
This example copies a file from a local Windows server to a remote Windows host. The actual functionality is defined in the win-copy
line. The directory location for the source file is entered in src
, and the directory location for the destination is entered in dest.
Free Resources