From 8ae9831439a8995748f46392321324d16b10b0d6 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Wed, 10 Oct 2012 18:41:02 -0400 Subject: [PATCH] Don't check in docsite static HTML, so folks will know to just edit the RST. --- docsite/YAMLSyntax.html | 259 ---- docsite/api.html | 474 ------ docsite/bestpractices.html | 318 ---- docsite/examples.html | 437 ------ docsite/genindex.html | 176 --- docsite/gettingstarted.html | 394 ----- docsite/glossary.html | 269 ---- docsite/index.html | 191 --- docsite/man.html | 202 --- docsite/moduledev.html | 498 ------ docsite/modules.html | 2701 --------------------------------- docsite/patterns.html | 377 ----- docsite/playbooks.html | 550 ------- docsite/playbooks2.html | 723 --------- docsite/search.html | 191 --- docsite/who_uses_ansible.html | 267 ---- 16 files changed, 8027 deletions(-) delete mode 100644 docsite/YAMLSyntax.html delete mode 100644 docsite/api.html delete mode 100644 docsite/bestpractices.html delete mode 100644 docsite/examples.html delete mode 100644 docsite/genindex.html delete mode 100644 docsite/gettingstarted.html delete mode 100644 docsite/glossary.html delete mode 100644 docsite/index.html delete mode 100644 docsite/man.html delete mode 100644 docsite/moduledev.html delete mode 100644 docsite/modules.html delete mode 100644 docsite/patterns.html delete mode 100644 docsite/playbooks.html delete mode 100644 docsite/playbooks2.html delete mode 100644 docsite/search.html delete mode 100644 docsite/who_uses_ansible.html diff --git a/docsite/YAMLSyntax.html b/docsite/YAMLSyntax.html deleted file mode 100644 index 141e3b997aa..00000000000 --- a/docsite/YAMLSyntax.html +++ /dev/null @@ -1,259 +0,0 @@ - - - - - - - - - YAML Syntax — Ansible Documentation - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - -
- -
-

YAML Syntax

-

This page provides a basic overview of correct YAML syntax, which is how Ansible -playbooks (our configuration management language) are expressed.

-

We use YAML because it is easier to read and write for humans than other common -data formats like XML or JSON. Further, there are libraries available for reading -and writing YAML in most programming languages.

-

You may also wish to read Playbooks at the same time to see how this -is used in practice.

-
-

YAML Basics

-

For ansible, nearly every YAML file starts with a list. -Each item in the list is a list of key/value pairs, commonly -called a “hash” or a “dictionary”. So, we need to know how -to write lists and dictionaries in YAML.

-

There’s another small quirk to YAML. All YAML files (regardless of their association with -ansible or not) should start with ---. This is just a YAML -format thing that means “this is the start of a document”.

-

All members of a list are lines beginning at the same indentation level starting -with a - (dash) character:

-
---
-# A list of tasty fruits
-- Apple
-- Orange
-- Strawberry
-- Mango
-
-

A dictionary is represented in a simple key: and value form:

-
---
-# An employee record
-name: John Eckersberg
-job: Developer
-skill: Elite
-
-

Dictionaries can also be represented in an abbreviated form if you really want to:

-
---
-# An employee record
-{name: John Eckersberg, job: Developer, skill: Elite}
-
-

Ansible doesn’t really use these too much, but you can also specify a -boolean value (true/false) in several forms:

-
---
-knows_oop: True
-likes_emacs: TRUE
-uses_cvs: false
-
-

Let’s combine what we learned so far in an arbitary YAML example. This really -has nothing to do with Ansible, but will give you a feel for the format:

-
---
-# An employee record
-name: John Eckersberg
-job: Developer
-skill: Elite
-employed: True
-foods:
-    - Apple
-    - Orange
-    - Strawberry
-    - Mango
-languages:
-    ruby: Elite
-    python: Elite
-    dotnet: Lame
-
-

That’s all you really need to know about YAML to get started writing -Ansible playbooks.

-
-

See also

-
-
Playbooks
-
Learn what playbooks can do and how to write/run them.
-
YAMLLint
-
YAML Lint (online) helps you debug YAML syntax if you are having problems
-
Github examples directory
-
Complete playbook files from the github project source
-
Mailing List
-
Questions? Help? Ideas? Stop by the list on Google Groups
-
irc.freenode.net
-
#ansible IRC chat channel
-
-
-
-
- - -
-
- - - \ No newline at end of file diff --git a/docsite/api.html b/docsite/api.html deleted file mode 100644 index b312d21466c..00000000000 --- a/docsite/api.html +++ /dev/null @@ -1,474 +0,0 @@ - - - - - - - - - API & Integrations — Ansible Documentation - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - -
- -
-

API & Integrations

-

There are several interesting ways to use Ansible from an API perspective. You can use -the Ansible python API to control nodes, you can extend Ansible to respond to various python events, -and you can plug in inventory data from external data sources. Ansible is written in its own -API so you have a considerable amount of power across the board.

- -
-

Python API

-

The Python API is very powerful, and is how the ansible CLI and ansible-playbook -are implemented.

-

It’s pretty simple:

-
import ansible.runner
-
-runner = ansible.runner.Runner(
-   module_name='ping',
-   module_args='',
-   pattern='web*',
-   forks=10
-)
-datastructure = runner.run()
-
-
-

The run method returns results per host, grouped by whether they -could be contacted or not. Return types are module specific, as -expressed in the ‘ansible-modules’ documentation.:

-
{
-    "dark" : {
-       "web1.example.com" : "failure message"
-    }
-    "contacted" : {
-       "web2.example.com" : 1
-    }
-}
-
-

A module can return any type of JSON data it wants, so Ansible can -be used as a framework to rapidly build powerful applications and scripts.

-
-

Detailed API Example

-

The following script prints out the uptime information for all hosts:

-
#!/usr/bin/python
-
-import ansible.runner
-import sys
-
-# construct the ansible runner and execute on all hosts
-results = ansible.runner.Runner(
-    pattern='*', forks=10,
-    module_name='command', module_args='/usr/bin/uptime',
-).run()
-
-if results is None:
-   print "No hosts found"
-   sys.exit(1)
-
-print "UP ***********"
-for (hostname, result) in results['contacted'].items():
-    if not 'failed' in result:
-        print "%s >>> %s" % (hostname, result['stdout'])
-
-print "FAILED *******"
-for (hostname, result) in results['contacted'].items():
-    if 'failed' in result:
-        print "%s >>> %s" % (hostname, result['msg'])
-
-print "DOWN *********"
-for (hostname, result) in results['dark'].items():
-    print "%s >>> %s" % (hostname, result)
-
-
-

Advanced programmers may also wish to read the source to ansible itself, for -it uses the Runner() API (with all available options) to implement the -command line tools ansible and ansible-playbook.

-
-
-
-

Plugins Repository

-

The remainder of features in the API docs have components available in ansible-plugins. Send us a github pull request if you develop any interesting features.

-
-
-

External Inventory Scripts

-

Often a user of a configuration management system will want to keep inventory -in a different system. Frequent examples include LDAP, Cobbler, -or a piece of expensive enterprisey CMDB software. Ansible easily supports all -of these options via an external inventory system. The plugins directory contains some of these already – including options for EC2/Eucalyptus and OpenStack, which will be detailed below.

-

It’s possible to write an external inventory script in any language. If you are familiar with Puppet terminology, this concept is basically the same as ‘external nodes’, with the slight difference that it also defines which hosts are managed.

-
-

Script Conventions

-

When the external node script is called with the single argument ‘–list’, the script must return a JSON hash/dictionary of all the groups to be managed, with a list of each host/IP as the value for each hash/dictionary element, like so:

-
{
-    'databases'  : [ 'host1.example.com', 'host2.example.com' ],
-    'webservers' : [ 'host2.example.com', 'host3.example.com' ],
-    'atlanta'    : [ 'host1.example.com', 'host4.example.com', 'host5.example.com' ]
-}
-
-
-

When called with the arguments ‘–host <hostname>’ (where <hostname> is a host from above), the script must return either an empty JSON -hash/dictionary, or a list of key/value variables to make available to templates or playbooks. Returning variables is optional, -if the script does not wish to do this, returning an empty hash/dictionary is the way to go:

-
{
-    'favcolor'   : 'red',
-    'ntpserver'  : 'wolf.example.com',
-    'monitoring' : 'pack.example.com'
-}
-
-
-
-
-

Example: The Cobbler External Inventory Script

-

It is expected that many Ansible users will also be Cobbler users. Cobbler has a generic -layer that allows it to represent data for multiple configuration management systems (even at the same time), and has -been referred to as a ‘lightweight CMDB’ by some admins. This particular script will communicate with Cobbler -using Cobbler’s XMLRPC API.

-

To tie Ansible’s inventory to Cobbler (optional), copy this script to /etc/ansible/hosts and chmod +x the file. cobblerd will now need -to be running when you are using Ansible.

-

Test the file by running ./etc/ansible/hosts directly. You should see some JSON data output, but it may not have -anything in it just yet.

-

Let’s explore what this does. In cobbler, assume a scenario somewhat like the following:

-
cobbler profile add --name=webserver --distro=CentOS6-x86_64
-cobbler profile edit --name=webserver --mgmt-classes="webserver" --ksmeta="a=2 b=3"
-cobbler system edit --name=foo --dns-name="foo.example.com" --mgmt-classes="atlanta" --ksmeta="c=4"
-cobbler system edit --name=bar --dns-name="bar.example.com" --mgmt-classes="atlanta" --ksmeta="c=5"
-
-

In the example above, the system ‘foo.example.com’ will be addressable by ansible directly, but will also be addressable when using the group names ‘webserver’ or ‘atlanta’. Since Ansible uses SSH, we’ll try to contract system foo over ‘foo.example.com’, only, never just ‘foo’. Similarly, if you try “ansible foo” it wouldn’t find the system... but “ansible ‘foo*’” would, because the system DNS name starts with ‘foo’.

-

The script doesn’t just provide host and group info. In addition, as a bonus, when the ‘setup’ module is run (which happens automatically when using playbooks), the variables ‘a’, ‘b’, and ‘c’ will all be auto-populated in the templates:

-
# file: /srv/motd.j2
-Welcome, I am templated with a value of a={{ a }}, b={{ b }}, and c={{ c }}
-
-

Which could be executed just like this:

-
ansible webserver -m setup
-ansible webserver -m template -a "src=/tmp/motd.j2 dest=/etc/motd"
-
-
-

Note

-

The name ‘webserver’ came from cobbler, as did the variables for -the config file. You can still pass in your own variables like -normal in Ansible, but variables from the external inventory script -will override any that have the same name.

-
-

So, with the template above (motd.j2), this would result in the following data being written to /etc/motd for system ‘foo’:

-
Welcome, I am templated with a value of a=2, b=3, and c=4
-
-

And on system ‘bar’ (bar.example.com):

-
Welcome, I am templated with a value of a=2, b=3, and c=5
-
-

And technically, though there is no major good reason to do it, this also works too:

-
ansible webserver -m shell -a "echo {{ a }}"
-
-

So in other words, you can use those variables in arguments/actions as well. You might use this to name -a conf.d file appropriately or something similar. Who knows?

-

So that’s the Cobbler integration support – using the cobbler script as an example, it should be trivial to adapt Ansible to pull inventory, as well as variable information, from any data source. If you create anything interesting, please share with the mailing list, and we can keep it in the source code tree for others to use.

-
-
-

Example: AWS EC2 External Inventory Script

-

If you use Amazon Web Services EC2, maintaining an inventory file might not be the best approach. For this reason, you can use the EC2 external inventory script.

-

You can use this script in one of two ways. The easiest is to use Ansible’s -i command line option and specify the path to the script.

-
-
ansible -i ec2.py -u ubuntu us-east-1d -m ping
-

The second option is to copy the script to /etc/ansible/hosts and chmod +x it. You will also need to copy the ec2.ini file to /etc/ansible/ec2.ini. Then you can run ansible as you would normally.

-

To successfully make an API call to AWS, you will need to configure Boto (the Python interface to AWS). There are a variety of methods available, but the simplest is just to export two environment variables:

-
-
export AWS_ACCESS_KEY_ID=’AK123’ -export AWS_SECRET_ACCESS_KEY=’abc123’
-

You can test the script by itself to make sure your config is correct

-
-
cd examples/scripts -./ec2_external_inventory.py –list
-

After a few moments, you should see your entire EC2 inventory across all regions in JSON.

-

Since each region requires its own API call, if you are only using a small set of regions, feel free to edit ec2.ini and list only the regions you are interested in. There are other config options in ec2.ini including cache control, and destination variables.

-

At their heart, inventory files are simply a mapping from some name to a destination address. The default ec2.ini settings are configured for running Ansible from outside EC2 (from your laptop for example). If you are running Ansible from within EC2, internal DNS names and IP addresses may make more sense than public DNS names. In this case, you can modify the destination_variable in ec2.ini to be the private DNS name of an instance. This is particularly important when running Ansible within a private subnet inside a VPC, where the only way to access an instance is via its private IP address. For VPC instances, vpc_destination_variable in ec2.ini provides a means of using which ever boto.ec2.instance variable makes the most sense for your use case.

-

The EC2 external inventory provides mappings to instances from several groups:

-
-
Instance ID
-
These are groups of one since instance IDs are unique. -e.g. -i-00112233 -i-a1b1c1d1
-
Region
-
A group of all instances in an AWS region. -e.g. -us-east-1 -us-west-2
-
Availability Zone
-
A group of all instances in an availability zone. -e.g. -us-east-1a -us-east-1b
-
Security Group
-
Instances belong to one or more security groups. A group is created for each security group, with all characters except alphanumerics, dashes (-) converted to underscores (_). Each group is prefixed by security_group_ -e.g. -security_group_default -security_group_webservers -security_group_Pete_s_Fancy_Group
-
Tags
-
Each instance can have a variety of key/value pairs associated with it called Tags. The most common tag key is ‘Name’, though anything is possible. Each key/value pair is its own group of instances, again with special characters converted to underscores, in the format tag_KEY_VALUE -e.g. -tag_Name_Web -tag_Name_redis-master-001 -tag_aws_cloudformation_logical-id_WebServerGroup
-
-

When the Ansible is interacting with a specific server, the EC2 inventory script is called again with the --host HOST option. This looks up the HOST in the index cache to get the instance ID, and then makes an API call to AWS to get information about that specific instance. It then makes information about that instance available as variables to your playbooks. Each variable is prefixed by ec2_. Here are some of the variables available:

-
    -
  • ec2_architecture
  • -
  • ec2_description
  • -
  • ec2_dns_name
  • -
  • ec2_id
  • -
  • ec2_image_id
  • -
  • ec2_instance_type
  • -
  • ec2_ip_address
  • -
  • ec2_kernel
  • -
  • ec2_key_name
  • -
  • ec2_launch_time
  • -
  • ec2_monitored
  • -
  • ec2_ownerId
  • -
  • ec2_placement
  • -
  • ec2_platform
  • -
  • ec2_previous_state
  • -
  • ec2_private_dns_name
  • -
  • ec2_private_ip_address
  • -
  • ec2_public_dns_name
  • -
  • ec2_ramdisk
  • -
  • ec2_region
  • -
  • ec2_root_device_name
  • -
  • ec2_root_device_type
  • -
  • ec2_security_group_ids
  • -
  • ec2_security_group_names
  • -
  • ec2_spot_instance_request_id
  • -
  • ec2_state
  • -
  • ec2_state_code
  • -
  • ec2_state_reason
  • -
  • ec2_status
  • -
  • ec2_subnet_id
  • -
  • ec2_tag_Name
  • -
  • ec2_tenancy
  • -
  • ec2_virtualization_type
  • -
  • ec2_vpc_id
  • -
-

Both ec2_security_group_ids and ec2_security_group_names are comma-separated lists of all security groups. Each EC2 tag is a variable in the format ec2_tag_KEY.

-

To see the complete list of variables available for an instance, run the script by itself:

-
cd examples/scripts
-./ec2_external_inventory.py --host ec2-12-12-12-12.compute-1.amazonaws.com
-
-
-
-

Example: OpenStack

-

Though not detailed here in as much depth as the EC2 module, there’s also a OpenStack Nova external inventory source in the plugins directory. See the inline comments in the module source.

-
-
-
-

Callback Plugins

-

Ansible can be configured via code to respond to external events. This can include enhancing logging, signalling an external software -system, or even (yes, really) making sound effects. Some examples are contained in the plugins directory.

-
-
-

Connection Type Plugins

-

By default, ansible ships with a ‘paramiko’ SSH, native ssh (just called ‘ssh’), and ‘local’ connection type, which can be used -in playbooks and with /usr/bin/ansible to decide how you want to talk to remote machines. The basics of these connection types -are covered in the ‘getting started’ section. Should you want to extend Ansible to support other transports (SNMP? Message bus? -Carrier Pigeon?) it’s as simple as copying the format of one of the existing modules and dropping it into the connection plugins -directory.

-
-

See also

-
-
Ansible Modules
-
List of built-in modules
-
Mailing List
-
Questions? Help? Ideas? Stop by the list on Google Groups
-
irc.freenode.net
-
#ansible IRC chat channel
-
-
-
-
- - -
-
- - - \ No newline at end of file diff --git a/docsite/bestpractices.html b/docsite/bestpractices.html deleted file mode 100644 index f88b33d649e..00000000000 --- a/docsite/bestpractices.html +++ /dev/null @@ -1,318 +0,0 @@ - - - - - - - - - Best Practices — Ansible Documentation - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - -
- -
-

Best Practices

-

Here are some tips for making the most of Ansible.

- -
-

Always Mention State

-

The ‘state’ parameter is optional to a lot of modules. Whether -‘state=present’ or ‘state=absent’, it’s always best to leave that -parameter in your playbooks to make it clear, especially as some -modules support additional states.

-
-
-

Group By Roles

-

A system can be in multiple groups. See Inventory & Patterns. Having groups named after things like -webservers and dbservers is repeated in the examples because it’s a very powerful concept.

-

This allows playbooks to target machines based on role, as well as to assign role specific variables -using the group variable system.

-
-
-

Directory Organization

-

Playbooks should be organized like this:

-
# root of source control repository
-├── acme/
-│   ├── setup.yml
-│   └── stop.yml
-├── files/
-│   └── some_file_path_foo.conf
-├── handlers/
-│   └── main.yml
-├── tasks/
-│   ├── setup.yml
-│   └── stop.yml
-├── templates/
-│   ├── etc_acme_conf_acme.conf
-│   └── etc_other_conf_other.conf
-├── vars/
-│   └── main.yml
-└── global_vars.yml
-
-

Any directories or files not needed can be omitted. Not all modules -may require ‘vars’ or ‘files’ sections, though most will require -‘handlers’, ‘tasks’, and ‘templates’. To review what each of -these sections do, see Playbooks and Advanced Playbooks.

-

The acme/setup.yml playbook would be as simple as:

-
---
-- hosts: webservers
-  user: root
-
-  vars_files:
-    - ../global_vars.yml
-    - vars/main.yml
-  tasks:
-    - include: tasks/setup.yml
-  handlers:
-    - include: handlers/main.yml
-
-

The tasks are individually broken out in ‘acme/tasks/setup.yml’, and handlers, which are common to all task files, -are contained in ‘acme/handlers/main.yml’. As a reminder, handlers are mostly just used to notify services to restart -when things change, and these are described in Playbooks.

-

Including more than one setup file or more than one handlers file is of course legal.

-
-
-

Bundling Ansible Modules With Playbooks

-

-New in version 0.5.

-

If a playbook has a ”./library” directory relative to it’s YAML file, -this directory can be used to add ansible modules that will -automatically be in the ansible module path. This is a great way to -keep modules that go with a playbook together.

-
-
-

Miscellaneous Tips

-

When you can do something simply, do something simply. Do not reach -to use every feature of Ansible together, all at once. Use what works -for you. For example, you should probably not need ‘vars’, -‘vars_files’, ‘vars_prompt’ and ‘–extra-vars’ all at once, -while also using an external inventory file.

-

Optimize for readability. Whitespace between sections of YAML -documents and in between tasks is strongly encouraged, as is usage of -YAML comments, which start with ‘#’. It is also useful to comment -at the top of each file the purpose of the individual file and the -author, including email address.

-

It is possible to leave off the ‘name’ for a given task, though it -is recommended to provide a descriptive comment about why something is -being done instead.

-

Use version control. Keep your playbooks and inventory file in git -(or another version control system), and commit when you make changes -to them. This way you have an audit trail describing when and why you -changed the rules automating your infrastructure.

-

Resist the urge to write the same playbooks and configuration files -for heterogeneous distributions. While lots of software packages -claim to make this easy on you, the configuration files are often -quite different, to the point where it would be easier to treat them -as different playbooks. This is why, for example, Ansible has a -separate ‘yum’ and ‘apt’ module. Yum and apt have different -capabilities, and we don’t want to code for the least common -denominator.

-

Use variables for user tunable settings versus having constants in the -tasks file or templates, so that it is easy to reconfigure a playbook. -Think about this as exposing the knobs to things you would like to -tweak.

-

Since a system can be in more than one group, if you have multiple -datacenters or sites, consider putting systems into groups by role, -but also different groups by geography. This allows you to assign -different variables to different geographies.

-
-

See also

-
-
YAML Syntax
-
Learn about YAML syntax
-
Playbooks
-
Review the basic playbook features
-
Ansible Modules
-
Learn about available modules
-
Module Development
-
Learn how to extend Ansible by writing your own modules
-
Inventory & Patterns
-
Learn about how to select hosts
-
Github examples directory
-
Complete playbook files from the github project source
-
Mailing List
-
Questions? Help? Ideas? Stop by the list on Google Groups
-
-
-
-
- - -
-
- - - \ No newline at end of file diff --git a/docsite/examples.html b/docsite/examples.html deleted file mode 100644 index a12b0f1ba3e..00000000000 --- a/docsite/examples.html +++ /dev/null @@ -1,437 +0,0 @@ - - - - - - - - - Command Line Examples And Next Steps — Ansible Documentation - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - -
- -
-

Command Line Examples And Next Steps

-

The following examples show how to use /usr/bin/ansible for running -ad hoc tasks. Start here.

-

For configuration management and deployments, you’ll want to pick up on -using /usr/bin/ansible-playbook – the concepts port over directly. -(See Playbooks for more information about those)

- -
-

Parallelism and Shell Commands

-

Let’s use ansible’s command line tool to reboot all web servers in Atlanta, 10 at a time. First, let’s -set up SSH-agent so it can remember our credentials:

-
$ ssh-agent bash
-$ ssh-add ~/.ssh/id_rsa.pub
-
-
-

If you don’t want to use ssh-agent and want to instead SSH with a -password instead of keys, you can with --ask-pass (-k), but -it’s much better to just use ssh-agent.

-

Now to run the command on all servers in a group, in this case, -atlanta, in 10 parallel forks:

-
$ ansible atlanta -a "/sbin/reboot" -f 10
-
-
-

In 0.7 and later, this will default to running from your user account. If you do not like this -behavior, pass in “-u username”. (In 0.6 and before, it defaulted to root. Most folks prefered -defaulting to the current user, so we changed it).

-

If you want to run commands as a different user, it looks like this:

-
$ ansible atlanta -a "/usr/bin/foo" -u username
-
-
-

If you want to run commands through sudo:

-
$ ansible atlanta -a "/usr/bin/foo" -u username --sudo [--ask-sudo-pass]
-
-
-

Use --ask-sudo-pass (-K) if you are not using passwordless -sudo. This will interactively prompt you for the password to use. -Use of passwordless sudo makes things easier to automate, but it’s not -required.

-

It is also possible to sudo to a user other than root using ---sudo-user (-U):

-
$ ansible atlanta -a "/usr/bin/foo" -u username -U otheruser [--ask-sudo-pass]
-
-
-

Ok, so those are basics. If you didn’t read about patterns and groups yet, go back and read Inventory & Patterns.

-

The -f 10 in the above specifies the usage of 10 simultaneous -processes. Normally commands also take a -m for module name, but -the default module name is ‘command’, so we didn’t need to -specify that all of the time. We’ll use -m in later examples to -run some other Ansible Modules.

-
-

Note

-

The command module requires absolute paths and does not -support shell variables. If we want to execute a module using a -shell, we can do those things, and also use pipe and redirection -operators. Read more about the differences on the Ansible Modules -page.

-
-

Using the shell module looks like this:

-
$ ansible raleigh -m shell -a 'echo $TERM'
-
-
-

When running any command with the ansible ad hoc CLI (as opposed to -Playbooks), pay particular attention to shell quoting rules, so -the shell doesn’t eat a variable before it gets passed to Ansible. -For example, using double vs single quotes in the above example would -evaluate the variable on the box you were on.

-

So far we’ve been demoing simple command execution, but most Ansible modules usually do not work like -simple scripts. They make the remote system look like you state, and run the commands necessary to -get it there. This is commonly referred to as ‘idempotence’, and is a core design goal of ansible. -However, we also recognize that running ad hoc commands is equally important, so Ansible easily supports both.

-
-
-

File Transfer

-

Here’s another use case for the /usr/bin/ansible command line. Ansible can SCP lots of files to multiple machines in parallel.

-

To transfer a file directly to many different servers:

-
$ ansible atlanta -m copy -a "src=/etc/hosts dest=/tmp/hosts"
-
-
-

If you use playbooks, you can also take advantage of the template module, -which takes this another step further. (See module and playbook documentation).

-

The file module allows changing ownership and permissions on files. These -same options can be passed directly to the copy module as well:

-
$ ansible webservers -m file -a "dest=/srv/foo/a.txt mode=600"
-$ ansible webservers -m file -a "dest=/srv/foo/b.txt mode=600 owner=mdehaan group=mdehaan"
-
-
-

The file module can also create directories, similar to mkdir -p:

-
$ ansible webservers -m file -a "dest=/path/to/c mode=644 owner=mdehaan group=mdehaan state=directory"
-
-
-

As well as delete directories (recursively) and delete files:

-
$ ansible webservers -m file -a "dest=/path/to/c state=absent"
-
-
-
-
-

Managing Packages

-

There are modules available for yum and apt. Here are some examples -with yum.

-

Ensure a package is installed, but don’t update it:

-
$ ansible webservers -m yum -a "pkg=acme state=installed"
-
-
-

Ensure a package is installed to a specific version:

-
$ ansible webservers -m yum -a "pkg=acme-1.5 state=installed"
-
-
-

Ensure a package is at the latest version:

-
$ ansible webservers -m yum -a "pkg=acme state=latest"
-
-
-

Ensure a package is not installed:

-
$ ansible webservers -m yum -a "pkg=acme state=removed"
-
-
-

Currently Ansible only has modules for managing packages with yum and apt. You can install -for other packages for now using the command module or (better!) contribute a module -for other package managers. Stop by the mailing list for info/details.

-
-
-

Users and Groups

-

The ‘user’ module allows easy creation and manipulation of -existing user accounts, as well as removal of user accounts that may -exist:

-
$ ansible all -m user -a "name=foo password=<crypted password here>"
-
-$ ansible all -m user -a "name=foo state=absent"
-
-
-

See the Ansible Modules section for details on all of the available options, including -how to manipulate groups and group membership.

-
-
-

Deploying From Source Control

-

Deploy your webapp straight from git:

-
$ ansible webservers -m git -a "repo=git://foo.example.org/repo.git dest=/srv/myapp version=HEAD"
-
-
-

Since ansible modules can notify change handlers it is possible to -tell ansible to run specific tasks when the code is updated, such as -deploying Perl/Python/PHP/Ruby directly from git and then restarting -apache.

-
-
-

Managing Services

-

Ensure a service is started on all webservers:

-
$ ansible webservers -m service -a "name=httpd state=started"
-
-
-

Alternatively, restart a service on all webservers:

-
$ ansible webservers -m service -a "name=httpd state=restarted"
-
-
-

Ensure a service is stopped:

-
$ ansible webservers -m service -a "name=httpd state=stopped"
-
-
-
-
-

Time Limited Background Operations

-

Long running operations can be backgrounded, and their status can be -checked on later. The same job ID is given to the same task on all -hosts, so you won’t lose track. If you kick hosts and don’t want -to poll, it looks like this:

-
$ ansible all -B 3600 -a "/usr/bin/long_running_operation --do-stuff"
-
-
-

If you do decide you want to check on the job status later, you can:

-
$ ansible all -m async_status -a "jid=123456789"
-
-
-

Polling is built-in and looks like this:

-
$ ansible all -B 1800 -P 60 -a "/usr/bin/long_running_operation --do-stuff"
-
-
-

The above example says “run for 30 minutes max (-B: 30*60=1800), -poll for status (-P) every 60 seconds”.

-

Poll mode is smart so all jobs will be started before polling will begin on any machine. -Be sure to use a high enough --forks value if you want to get all of your jobs started -very quickly. After the time limit (in seconds) runs out (-B), the process on -the remote nodes will be terminated.

-

Typically you’ll be only be backgrounding long-running -shell commands or software upgrades only. Backgrounding the copy module does not do a background file transfer. Playbooks also support polling, and have a simplified syntax for this.

-
-
-

Limiting Selected Hosts

-

-New in version 0.7.

-

What hosts you select to manage can be additionally constrained by using the ‘–limit’ parameter or -by using ‘batch’ (or ‘range’) selectors.

-

As mentioned above, patterns can be strung together to select hosts in more than one group:

-
$ ansible webservers:dbservers -m command -a "/bin/foo xyz"
-
-
-

This is an “or” condition. If you want to further constrain the selection, use –limit, which -also works with ansible-playbook:

-
$ ansible webservers:dbservers -m command -a "/bin/foo xyz" region
-
-
-

Now let’s talk about range selection. Suppose you have 1000 servers in group ‘datacenter’, but only want to target one at a time. This is also easy:

-
$ ansible webservers[0-99] -m command -a "/bin/foo xyz"
-$ ansible webservers[100-199] -m command -a "/bin/foo xyz"
-
-
-

This will select the first 100, then the second 100, host entries in the webservers group. (It does not matter -what their names or IP addresses are).

-

Both of these methods can be used at the same time, and ranges can also be passed to the –limit parameter.

-
-
-

Configuration & Defaults

-

-New in version 0.7.

-

Ansible has an optional configuration file that can be used to tune settings and also eliminate the need to pass various command line flags. Ansible will look for the config file in the following order, using -the first config file it finds present:

-
    -
  1. File specified by the ANSIBLE_CONFIG environment variable
  2. -
  3. ansible.cfg in the current working directory. (version 0.8 and up)
  4. -
  5. ~/.ansible.cfg
  6. -
  7. /etc/ansible/ansible.cfg
  8. -
-

For those running from source, a sample configuration file lives in the examples/ directory. The RPM will install configuration into /etc/ansible/ansible.cfg automatically.

-
-

See also

-
-
Ansible Modules
-
A list of available modules
-
Playbooks
-
Using ansible for configuration management & deployment
-
Mailing List
-
Questions? Help? Ideas? Stop by the list on Google Groups
-
irc.freenode.net
-
#ansible IRC chat channel
-
-
-
-
- - -
-
- - - \ No newline at end of file diff --git a/docsite/genindex.html b/docsite/genindex.html deleted file mode 100644 index 5534d804539..00000000000 --- a/docsite/genindex.html +++ /dev/null @@ -1,176 +0,0 @@ - - - - - - - - - - - Index — Ansible Documentation - - - - - - - - - - - - - - - - - - - - - -
- -
- - -
- - -

Index

- -
- -
- - -
-
- - - \ No newline at end of file diff --git a/docsite/gettingstarted.html b/docsite/gettingstarted.html deleted file mode 100644 index 690ff4758ed..00000000000 --- a/docsite/gettingstarted.html +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - - Getting Started — Ansible Documentation - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - -
- -
-

Getting Started

- -
-

Requirements

-

Requirements for Ansible are extremely minimal.

-

Ansible is written for Python 2.6. If you are running Python 2.5 on an “Enterprise Linux” variant, -your distribution can easily install 2.6 (see instructions in the next section). Newer versions -of Linux and OS X should already have 2.6.

-

In additon to Python 2.6, you will want the following packages:

-
    -
  • paramiko
  • -
  • PyYAML
  • -
  • python-jinja2
  • -
-

On the managed nodes, you only need Python 2.4 or later, but if you are are running less than Python 2.6 on them, you will -also need:

-
    -
  • python-simplejson
  • -
-
-

Note

-

Ansible’s “raw” module (for executing commands in a quick and dirty -way) and the copy module – some of the most basic features in -ansible – don’t even need that. So technically, you can use -Ansible to install python-simplejson using the raw module, which -then allows you to use everything else. (That’s jumping ahead -though.)

-
-
-
-

Python 2.6 EPEL instructions for RHEL and CentOS 5

-

These distributions don’t have Python 2.6 by default, but it is easily -installable. If you have not already done so, configure EPEL

-
$ yum install python26 python26-PyYAML python26-paramiko python26-jinja2
-
-
-
-
-

Getting Ansible

-

If you are interested in using all the latest features, you may wish to keep up to date -with the development branch of the git checkout. This also makes it easiest to contribute -back to the project.

-

Instructions for installing from source are below.

-

Ansible’s release cycles are about one month long. Due to this -short release cycle, any bugs will generally be fixed in the next release versus maintaining -backports on the stable branch.

-

You may also wish to follow the Github project if -you have a github account. This is also where we keep the issue tracker for sharing -bugs and feature ideas.

-
-

Running From Checkout

-

Ansible is trivially easy to run from a checkout, root permissions are not required -to use it:

-
$ git clone git://github.com/ansible/ansible.git
-$ cd ./ansible
-$ source ./hacking/env-setup
-
-
-

You can optionally specify an inventory file (see Inventory & Patterns) other than /etc/ansible/hosts:

-
$ echo "127.0.0.1" > ~/ansible_hosts
-$ export ANSIBLE_HOSTS=~/ansible_hosts
-
-
-

Now let’s test things:

-
$ ansible all -m ping --ask-pass
-
-
-
-
-

Make Install

-

If you are not working from a distribution where Ansible is packaged yet, you can install Ansible -using “make install”. This is done through python-distutils:

-
$ git clone git://github.com/ansible/ansible.git
-$ cd ./ansible
-$ sudo make install
-
-
-
-
-

Via RPM

-

RPMs for the last Ansible release are available for EPEL 6 and currently supported -Fedora distributions. Ansible itself can manage earlier operating -systems that contain python 2.4 or higher.

-
# install the epel-release RPM if needed on CentOS, RHEL, or Scientific Linux
-$ sudo yum install ansible
-
-
-

You can also use the make rpm command to build an RPM you can -distribute and install:

-
$ git clone git://github.com/ansible/ansible.git
-$ cd ./ansible
-$ make rpm
-$ sudo rpm -Uvh ~/rpmbuild/ansible-*.noarch.rpm
-
-
-
-
-

Debian, Gentoo, Arch, Others

-

Ubuntu builds are available in a PPA here

-

Debian/Ubuntu package recipes can also be built from the source checkout, run:

-
$ make debian
-
-
-

Gentoo eBuilds are available on github here

-

An Arch PKGBUILD is available on AUR -If you have python3 installed on Arch, you probably want to symlink python to python2:

-
$ sudo ln -sf /usr/bin/python2 /usr/bin/python
-
-
-

If you would like to package Ansible for Homebrew, BSD, or others, -please stop by the mailing list and say hi!

-
-
-

Tagged Releases

-

Tagged releases are available as tar.gz files from the Ansible github -project page:

- -
-
-
-

Choosing Between Paramiko and Native SSH

-

By default, ansible uses paramiko to talk to managed nodes over SSH. Paramiko is fast, works -very transparently, requires no configuration, and is a good choice for most users. -However, it does not support some advanced SSH features that folks will want to use.

-

-New in version 0.5.

-

If you want to leverage more advanced SSH features (such as Kerberized -SSH or jump hosts), pass the flag “–connection=ssh” to any ansible -command, or set the ANSIBLE_TRANSPORT environment variable to -‘ssh’. This will cause Ansible to use openssh tools instead.

-

If ANSIBLE_SSH_ARGS are not set, ansible will try to use some sensible ControlMaster options -by default. You are free to override this environment variable, but should still pass ControlMaster -options to ensure performance of this transport. With ControlMaster in use, both transports -are roughly the same speed. Without CM, the binary ssh transport is signficantly slower.

-

If none of this makes sense to you, the default paramiko option is probably fine.

-
-
-

Your first commands

-

Now that you’ve installed Ansible, it’s time to test it.

-

Edit (or create) /etc/ansible/hosts and put one or more remote systems in it, for -which you have your SSH key in authorized_keys:

-
192.168.1.50
-aserver.example.org
-bserver.example.org
-
-

Set up SSH agent to avoid retyping passwords:

-
$ ssh-agent bash
-$ ssh-add ~/.ssh/id_rsa
-
-
-

(Depending on your setup, you may wish to ansible’s –private-key-file option to specify a pem file instead)

-

Now ping all your nodes:

-
$ ansible all -m ping
-
-
-

In Ansible 0.7 and later, ansible will attempt to remote connect to the machines using your current -user name, just like SSH would. In 0.6 and before, this actually defaults to ‘root’ (we liked the current -user behavior better). To override the remote user name, just use the ‘-u’ parameter.

-

If you would like to access sudo mode, there are also flags to do that:

-
# as bruce
-$ ansible all -m ping -u bruce
-# as bruce, sudoing to root
-$ ansible all -m ping -u bruce --sudo
-# as bruce, sudoing to batman
-$ ansible all -m ping -u bruce --sudo --sudo-user batman
-
-
-

Now run a live command on all of your nodes:

-
$ ansible all -a "/bin/echo hello"
-
-
-

Congratulations. You’ve just contacted your nodes with Ansible. It’s -now time to read some of the more real-world Command Line Examples And Next Steps, and explore -what you can do with different modules, as well as the Ansible -Playbooks language. Ansible is not just about running commands, it -also has powerful configuration management and deployment features. There’s more to -explore, but you already have a fully working infrastructure!

-
-

See also

-
-
Command Line Examples And Next Steps
-
Examples of basic commands
-
Playbooks
-
Learning ansible’s configuration management language
-
Mailing List
-
Questions? Help? Ideas? Stop by the list on Google Groups
-
irc.freenode.net
-
#ansible IRC chat channel
-
-
-
-
- - -
-
- - - \ No newline at end of file diff --git a/docsite/glossary.html b/docsite/glossary.html deleted file mode 100644 index ee6beb31e39..00000000000 --- a/docsite/glossary.html +++ /dev/null @@ -1,269 +0,0 @@ - - - - - - - - Glossary — Ansible - SSH-Based Configuration Management & Deployment - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-Fork me on GitHub - - -
- Ansible
-
- -
-

Glossary

-

After reading through the rest of the documentation, it may be helpful to review some terms.

-

ansible – from science fiction, a device for communicating instanteously over large distances.

-

ansible – When speaking of /usr/bin/ansible, a tool for ad-hoc task execution on a group of hosts. This constrasts with /usr/bin/ansible-playbook, which is a full on configuration management and orchestration tool built on top of these fundamentals. Both come with ‘ansible’, the application.

-

action – the part of a task that specifies what module to run and what arguments to send it

-

async – the act of running a ansible task in the background, potentially polling it for completion. This is useful for kicking off tasks where the result is not important, or in executing tasks that would exceed the SSH timeout.

-

cobbler – a kickstart, mirroring, power management, and miscellaneous datacenter management tool that Michael wrote before Ansible, and is frequently used with it. See Cobbler

-

common module code – a facility in which Ansible modules written in Python can minimize boilerplate code for argument validation and returning values. This is not available to non-Python modules but modules can still be written in languages other than Python.

-

connection – how Ansible connects to and manages remote hosts. Paramiko and native ssh are the main options, though -there is also a local connection mode.

-

cowsay – a special utility program that, if installed, greatly enhances the clarity of ansible-playbook output.

-

daisy chaining – comes up in development discussions. It’s how in Ansible one module (like copy or template) can -use parameters supported by the file module by requesting the file module be run after the copy module. For example, if specifying a file be templated, we can also specify the mode and owner because the file module is automatically daisy-chained -after the file module.

-

DSL – domain specific language. The idea of making a special “programming” language or a subset of a language to build a tool out of. Ansible doesn’t believe in these, and instead treats it’s playbook language as a data format.

-

env-setup – a very useful script in the “hacking” directory of an ansible checkout. Sourcing this script makes it very easy to run ansible from source without doing any installation.

-

external inventory script – the act of using an executable script in place of an ansible inventory file, so that ansible will invoke the script when needed to ask about what hosts it is managing and variables related to those hosts.

-

fact – a variable discovered about a remote host, rather than configured in a config file. Facts can include -the system architecture, the hostname, the operating system version, and so on. facts can be used in configuration -files.

-

forks – the level of parallelism used with a /usr/bin/ansible or /usr/bin/ansible-playbook command. Ansible executes multiple remote management commands in parallel to get things done faster.

-

func – an earlier ad-hoc execution tool that is the basis of some of the ideas in Ansible. Michael wrote Func with some colleagues from Red Hat, and a later tool called taboot built on Func helped inspire the playbooks language. Func didn’t have a configuration management language on top of it, nor did it use SSH, but it helped pave the way for several other tools.

-

handler – a special class of a task that is not run unless a given task registers a change event. Handlers are most -frequently used for restarting services when the contents of configuration files change.

-

idempotent – when applied to configuration management, this means that running a given task twice does not produce -an unexpected effect on the system. Mathematically, F(x) = F(F(x)). Ansible’s core modules all support this concept -but Ansible does not force this upon you.

-

include – a playbook, handler, or variable data loaded from another file

-

infrastructure as code – the practice of treating configuration, management, and deployment of systems as a software project. Ansible doesn’t really believe in this and tries to simplify things by making a simpler language that is easier to write and audit, and is therefore easier to understand by all parties involved. More advanced takes on I.A.C. use actual programming languages to describe configurations.

-

inventory – ansible keeps track of what hosts you are managing, and allows them to be put in groups for easier selection. This file is by default in a simple INI format, but can be replaced with an ‘external inventory script’

-

Jinja2 – Ansible uses this as a templating language for the ‘template’ module.

-

JSON – the format Ansible modules use to return data over the wire. “Java Script Object Notation”

-

module – a reusable unit of logic that tells Ansible how to do things on remote machines. Ansible ships with many modules written in Python, but modules can be written in any language. Modules return structured data in JSON.

-

notify – what a task does when it detects that something has changed on the remote system. A task notifying a handler -means it is sending a message to the handler that it needs to run at the end of a playbook execution.

-

paramiko – the default connection type for ansible uses a pure-Python SSH library called paramiko. It is generally -easier to set up than native SSH but does not offer as many configuration options and does not support Kerberized SSH.

-

pattern – a selector that can match host or group names using wildcards. Patterns are used in plays or in ad-hoc executions of /usr/bin/ansible to target groups of hosts to manage.

-

play – a group of ansible tasks that are to be executed on the same set of hosts. A play is always run by the same user account and may optionally sudo to a particular user after connecting. In addition to a list of tasks, a play may also choose to define variables or include them from other files, all of which are shared with each task in the play.

-

playbook – a list of ansible plays grouped together in a single file, which are run top to bottom. Each play may select different hosts and have different tasks. A playbook is analogous to a Chef recipe, a Puppet manifest, a CFEngine “promise”. Playbooks can be broken up into more than one file using includes, in which case it’s still ok to call it a playbook.

-

pull – the act of a managed system phoning home to ask how it is configured. This is useful in large scale out scenarios or for periodic automatic system remediation.

-

push – the act of reaching out to systems you want to manage rather than them phoning home. This is Ansible’s default -mode, but pull is also supported via the ‘ansible-pull’ script.

-

runner – comes up in development discussions. a core component of the ansible code that runs a single module/task against a given set of hosts. /usr/bin/ansible makes use of runner directly. Playbooks instantiate multiple instances of runner, -one for each task in a playbook.

-

setup cache – comes up in development discussions. The setup cache is a mechanism of storing fact results from various -systems and makes them available as variables in action lines and templates

-

SSH – secure shell. Ansible by default uses SSH to talk to remote hosts because it is already there and very secure. It does not require any additional daemons.

-

task – one of many ansible modules to execute on a given set of hosts, and the parameters to use when calling it. -A task has a name, an ‘action’, and other optional variables. Making sure a package is installed, or a file -is templated and transferred, is the example of a task.

-

template – the act of taking a file with variable placeholders in it and substituting variables to make a final file. Templating is frequently used to place configuration files.

-

test-module – a useful script in the “hacking” directory of an ansible checkout for running a module locally, without ansible’s core code in the way. Used when developing or debugging modules.

-

Van Halen – the great American Rock Band, known for great instrumental guitar work and also songs about Alien Abductions. All Ansible releases are code named after Van Halen songs. C’mon Dave, gimme a break.

-

YAML – the core language format for ansible playbooks and include files. Stands for “YAML Ain’t Markup Language”. YAML can be taken to extremes where it is difficult to write and read, but Ansible uses a relatively simple dialect and minimal levels of nesting.

-
- - -
-
- - - \ No newline at end of file diff --git a/docsite/index.html b/docsite/index.html deleted file mode 100644 index b77e61d821d..00000000000 --- a/docsite/index.html +++ /dev/null @@ -1,191 +0,0 @@ - - - - - - - - - Contents — Ansible Documentation - - - - - - - - - - - - - - - - - - - - - - -
- -
- - -
- - - - -
-
- - - \ No newline at end of file diff --git a/docsite/man.html b/docsite/man.html deleted file mode 100644 index 6f70134c644..00000000000 --- a/docsite/man.html +++ /dev/null @@ -1,202 +0,0 @@ - - - - - - - - Man Pages — Ansible - SSH-Based Configuration Management & Deployment - - - - - - - - - - - - - - - - - -
- -
- - -
- -
-

Man Pages

-

Ansible’s man pages list available command line options. See the rest of the web site for -examples of these tools in use.

-
-

ansible(1)

- -
-
-

ansible-playbook(1)

- -
-

See also

-
-
Command Line Examples
-
Examples of basic commands
-
Ansible Modules
-
List of built-in modules
-
Playbooks
-
Learning ansible’s configuration management language
-
Mailing List
-
Questions? Help? Ideas? Stop by the list on Google Groups
-
irc.freenode.net
-
#ansible IRC chat channel
-
-
-
-
- - -
- - - \ No newline at end of file diff --git a/docsite/moduledev.html b/docsite/moduledev.html deleted file mode 100644 index 70436d9f1fe..00000000000 --- a/docsite/moduledev.html +++ /dev/null @@ -1,498 +0,0 @@ - - - - - - - - - Module Development — Ansible Documentation - - - - - - - - - - - - - - - - - - - - - - -
- -
- - -
- -
-

Module Development

-

Ansible modules are reusable units of magic that can be used by the Ansible API, -or by the ansible or ansible-playbook programs.

-

Modules can be written in any language and are found in the path specified -by ANSIBLE_LIBRARY_PATH or the --module-path command line option.

- -
-

Tutorial

-

Let’s build a module to get and set the system time. For starters, let’s build -a module that just outputs the current time.

-

We are going to use Python here but any language is possible. Only File I/O and outputing to standard -out are required. So, bash, C++, clojure, Python, Ruby, whatever you want -is fine.

-

Now Python Ansible modules contain some extremely powerful shortcuts (that all the core modules use) -but first we are going to build a module the very hard way. The reason we do this is because modules -written in any language OTHER than Python are going to have to do exactly this. We’ll show the easy -way later.

-

So, here’s an example. You would never really need to build a module to set the system time, -the ‘command’ module could already be used to do this. Though we’re going to make one.

-

Reading the modules that come with ansible (linked above) is a great way to learn how to write -modules. Keep in mind, though, that some modules in ansible’s source tree are internalisms, -so look at service or yum, and don’t stare too close into things like async_wrapper or -you’ll turn to stone. Nobody ever executes async_wrapper directly.

-

Ok, let’s get going with an example. We’ll use Python. For starters, save this as a file named time:

-
#!/usr/bin/python
-
-import datetime
-import json
-
-date = str(datetime.datetime.now())
-print json.dumps({
-    "time" : date
-})
-
-
-
-
-

Testing Modules

-

There’s a useful test script in the source checkout for ansible:

-
git clone git@github.com:ansible/ansible.git
-chmod +x ansible/hacking/test-module
-
-

Let’s run the script you just wrote with that:

-
ansible/hacking/test-module -m ./time
-
-

You should see output that looks something like this:

-
{u'time': u'2012-03-14 22:13:48.539183'}
-
-
-

If you did not, you might have a typo in your module, so recheck it and try again.

-
-
-

Reading Input

-

Let’s modify the module to allow setting the current time. We’ll do this by seeing -if a key value pair in the form time=<string> is passed in to the module.

-

Ansible internally saves arguments to an arguments file. So we must read the file -and parse it. The arguments file is just a string, so any form of arguments are legal. -Here we’ll do some basic parsing to treat the input as key=value.

-

The example usage we are trying to achieve to set the time is:

-
time time="March 14 22:10"
-
-

If no time parameter is set, we’ll just leave the time as is and return the current time.

-

Let’s look at the code. Read the comments as we’ll explain as we go. Note that this -is highly verbose because it’s intended as an educational example. You can write modules -a lot shorter than this:

-
#!/usr/bin/python
-
-# import some python modules that we'll use.  These are all
-# available in Python's core
-
-import datetime
-import sys
-import json
-import os
-import shlex
-
-# read the argument string from the arguments file
-args_file = sys.argv[1]
-args_data = file(args_file).read()
-
-# for this module, we're going to do key=value style arguments
-# this is up to each module to decide what it wants, but all
-# core modules besides 'command' and 'shell' take key=value
-# so this is highly recommended
-
-arguments = shlex.split(args_data)
-for arg in arguments:
-
-    # ignore any arguments without an equals in it
-    if arg.find("=") != -1:
-
-        (key, value) = arg.split("=")
-
-        # if setting the time, the key 'time'
-        # will contain the value we want to set the time to
-
-        if key == "time":
-
-            # now we'll affect the change.  Many modules
-            # will strive to be 'idempotent', meaning they
-            # will only make changes when the desired state
-            # expressed to the module does not match
-            # the current state.  Look at 'service'
-            # or 'yum' in the main git tree for an example
-            # of how that might look.
-
-            rc = os.system("date -s \"%s\"" % value)
-
-            # always handle all possible errors
-            #
-            # when returning a failure, include 'failed'
-            # in the return data, and explain the failure
-            # in 'msg'.  Both of these conventions are
-            # required however additional keys and values
-            # can be added.
-
-            if rc != 0:
-                print json.dumps({
-                    "failed" : True,
-                    "msg"    : "failed setting the time"
-                })
-                sys.exit(1)
-
-            # when things do not fail, we do not
-            # have any restrictions on what kinds of
-            # data are returned, but it's always a
-            # good idea to include whether or not
-            # a change was made, as that will allow
-            # notifiers to be used in playbooks.
-
-            date = str(datetime.datetime.now())
-            print json.dumps({
-                "time" : date,
-                "changed" : True
-            })
-            sys.exit(0)
-
-# if no parameters are sent, the module may or
-# may not error out, this one will just
-# return the time
-
-date = str(datetime.datetime.now())
-print json.dumps({
-    "time" : date
-})
-
-
-

Let’s test that module:

-
ansible/hacking/test-module -m ./time -a time=\"March 14 12:23\"
-
-

This should return something like:

-
{"changed": True, "time": "2012-03-14 12:23:00.000307"}
-
-
-
-
-

Module Provided ‘Facts’

-

The ‘setup’ module that ships with Ansible provides many variables about a system that can be used in playbooks -and templates. However, it’s possible to also add your own facts without modifying the system module. To do -this, just have the module return a ansible_facts key, like so, along with other return data:

-
{
-    "changed" : True,
-    "rc" : 5,
-    "ansible_facts" : {
-        "leptons" : 5000
-        "colors" : {
-            "red"   : "FF0000",
-            "white" : "FFFFFF"
-        }
-    }
-}
-
-

These ‘facts’ will be available to all statements called after that module (but not before) in the playbook. -A good idea might be make a module called ‘site_facts’ and always call it at the top of each playbook, though -we’re always open to improving the selection of core facts in Ansible as well.

-
-
-

Common Module Boilerplate

-

As mentioned, if you are writing a module in Python, there are some very powerful shortcuts you can use. -Modules are still transferred as one file, but an arguments file is no longer needed, so these are not -only shorter in terms of code, they are actually FASTER in terms of execution time.

-

Rather than mention these here, the best way to learn is to read some of the source of the modules that come with Ansible.

-

The ‘group’ and ‘user’ modules are reasonably non-trival and showcase what this looks like.

-

Key parts include always ending the module file with:

-
# include magic from lib/ansible/module_common.py
-#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
-main()
-
-
-

And instantiating the module class like:

-
module = AnsibleModule(
-    argument_spec = dict(
-        state     = dict(default='present', choices=['present', 'absent']),
-        name      = dict(required=True),
-        enabled   = dict(required=True, choices=BOOLEANS),
-        something = dict(aliases=['whatever'])
-    )
-)
-
-
-

The AnsibleModule provides lots of common code for handling returns, parses your arguments -for you, and allows you to check inputs.

-

Successful returns are made like this:

-
module.exit_json(changed=True, something_else=12345)
-
-
-

And failures are just as simple (where ‘msg’ is a required parameter to explain the error):

-
module.fail_json(msg="Something fatal happened")
-
-
-

There are also other useful functions in the module class, such as module.md5(path). See -lib/ansible/module_common.py in the source checkout for implementation details.

-

Again, modules developed this way are best tested with the hacking/test-module script in the git -source checkout. Because of the magic involved, this is really the only way the scripts -can function outside of Ansible.

-

If submitting a module to ansible’s core code, which we encourage, use of the AnsibleModule -class is required.

-
-
-

Common Pitfalls

-

You should also never do this in a module:

-
print "some status message"
-
-
-

Because the output is supposed to be valid JSON. Except that’s not quite true, -but we’ll get to that later.

-

Modules must not output anything on standard error, because the system will merge -standard out with standard error and prevent the JSON from parsing. Capturing standard -error and returning it as a variable in the JSON on standard out is fine, and is, in fact, -how the command module is implemented.

-

If a module returns stderr or otherwise fails to produce valid JSON, the actual output -will still be shown in Ansible, but the command will not succeed.

-

Always use the hacking/test-module script when developing modules and it will warn -you about these kind of things.

-
-
-

Conventions/Recomendations

-

As a reminder from the example code above, here are some basic conventions -and guidelines:

-
    -
  • If the module is addressing an object, the parameter for that object should be called ‘name’ whenever possible, or accept ‘name’ as an alias.
  • -
  • If you have a company module that returns facts specific to your installations, a good name for this module is site_facts.
  • -
  • Modules accepting boolean status should generally accept ‘yes’, ‘no’, ‘true’, ‘false’, or anything else a user may likely throw at them. The AnsibleModule common code supports this with “choices=BOOLEANS” and a module.boolean(value) casting function.
  • -
  • Include a minimum of dependencies if possible. If there are dependencies, document them at the top of the module file, and have the module raise JSON error messages when the import fails.
  • -
  • Modules must be self contained in one file to be auto-transferred by ansible.
  • -
  • If packaging modules in an RPM, they only need to be installed on the control machine and should be dropped into /usr/share/ansible. This is entirely optional and up to you.
  • -
  • Modules should return JSON or key=value results all on one line. JSON is best if you can do JSON. All return types must be hashes (dictionaries) although they can be nested. Lists or simple scalar values are not supported, though they can be trivially contained inside a dictionary.
  • -
  • In the event of failure, a key of ‘failed’ should be included, along with a string explanation in ‘msg’. Modules that raise tracebacks (stacktraces) are generally considered ‘poor’ modules, though Ansible can deal with these returns and will automatically convert anything unparseable into a failed result. If you are using the AnsibleModule common Python code, the ‘failed’ element will be included for you automatically when you call ‘fail_json’.
  • -
  • Return codes from modules are not actually not signficant, but continue on with 0=success and non-zero=failure for reasons of future proofing.
  • -
  • As results from many hosts will be aggregrated at once, modules should return only relevant output. Returning the entire contents of a log file is generally bad form.
  • -
-
-
-

Shorthand Vs JSON

-

To make it easier to write modules in bash and in cases where a JSON -module might not be available, it is acceptable for a module to return -key=value output all on one line, like this. The Ansible parser -will know what to do:

-
somekey=1 somevalue=2 rc=3 favcolor=red
-
-

If you’re writing a module in Python or Ruby or whatever, though, returning -JSON is probably the simplest way to go.

-
-
-

Sharing Your Module

-

If you think your module is generally useful to others, a good place to share it -is in Ansible Resources. This is maintained -as a simple repo with pointers to other github projects.

-

Contrib modules here can be implemented in a variety of languages. -We would like to build up as many of these as possible in as many languages as possible.

-

Ansible Mailing List

-
-
-

Getting Your Module Into Core

-

High-quality modules with minimal dependencies -can be included in the core, but core modules (just due to the programming -preferences of the developers) will need to be implemented in Python and use -the AnsibleModule common code, and should generally use consistent arguments with the rest of -the program. Stop by the mailing list to inquire about requirements.

-
-

See also

-
-
Ansible Modules
-
Learn about available modules
-
Ansible Resources
-
User contributed playbooks, modules, and articles
-
Github modules directory
-
Browse source of core modules
-
Mailing List
-
Questions? Help? Ideas? Stop by the list on Google Groups
-
irc.freenode.net
-
#ansible IRC chat channel
-
-
-
-
- - -
-
- - - \ No newline at end of file diff --git a/docsite/modules.html b/docsite/modules.html deleted file mode 100644 index 19fa6842b72..00000000000 --- a/docsite/modules.html +++ /dev/null @@ -1,2701 +0,0 @@ - - - - - - - - - Ansible Modules — Ansible Documentation - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - -
- -
-

Ansible Modules

- -
-

Introduction

-

Ansible ships with a number of modules (called the ‘module library’) -that can be executed directly on remote hosts or through Playbooks. -Users can also write their own modules. These modules can control system -resources, like services, packages, or files (anything really), or -handle executing system commands.

-

Let’s review how we execute three different modules from the command line:

-
ansible webservers -m service -a "name=httpd state=running"
-ansible webservers -m ping
-ansible webservers -m command -a "/sbin/reboot -t now"
-
-

Each module supports taking arguments. Nearly all modules take key=value -arguments, space delimited. Some modules take no arguments, and the -command/shell modules simply take the string of the command you want to run.

-

From playbooks, Ansible modules are executed in a very similar way:

-
- name: reboot the servers
-  action: command /sbin/reboot -t now
-
-

All modules technically return JSON format data, though if you are using the -command line or playbooks, you don’t really need to know much about -that. If you’re writing your own module, you care, and this means you do -not have to write modules in any particular language – you get to choose.

-

Modules are idempotent, meaning they will seek to avoid changes to the system unless a change needs to be made. When using Ansible -playbooks, these modules can trigger ‘change events’ in the form of notifying ‘handlers’ -to run additional tasks.

-

Let’s see what’s available in the Ansible module library, out of the box:

-
-
-

apt

-

-New in version 0.0.2.

-

Manages apt-packages (such as for Debian/Ubuntu).

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
parameterrequireddefaultchoicescomments
purgenono
  • yes
  • no
Will force purging of configuration files if the module state is set to absent.
statenopresent
  • installed
  • latest
  • remove
  • absent
  • present
Indicates the desired package state
forcenono
  • yes
  • no
If yes, force installs/removes.
pkgyes
    A package name or package specifier with version, like foo or foo=1.0
    update_cachenono
    • yes
    • no
    Run the equivalent of apt-get update before the operation. Can be run as part of the package installation or as a seperate step
    default_releaseno
      Corresponds to the -t option for apt and sets pin priorities
      install_recommendsnono
      • yes
      • no
      Corresponds to the --no-install-recommends option for apt, default behavior works as apt's default behavior, no does not install recommended packages. Suggested packages are never installed.

      Update repositories cache and install foo package

      -apt pkg=foo update-cache=yes
      -

      -

      Remove foo package

      -apt pkg=foo state=removed
      -

      -

      Install the the package foo

      -apt pkg=foo state=installed
      -

      -

      Install the version '1.00' of package foo

      -apt pkg=foo=1.00 state=installed
      -

      -

      Update the repository cache and update package ngnix to latest version using default release squeeze-backport

      -apt pkg=nginx state=latest default-release=squeeze-backports update-cache=yes
      -

      -

      Install latest version of openjdk-6-jdk ignoring install-recomands

      -apt pkg=openjdk-6-jdk state=latest install-recommends=no
      -

      -
      -
      -

      apt_repository

      -

      -New in version 0.7.

      -

      Manages apt repositores (such as for Debian/Ubuntu).

      - - - - - - - - - - - - - - - - - - - - - - -
      parameterrequireddefaultchoicescomments
      repoyes
        The repository name/value
        statenopresent
        • present
        • absent
        The repository state

        Add nginx stable repository from PPA

        -apt_repository repo=ppa://nginx/stable
        -

        -

        Add specified repository into sources.

        -apt_repository repo='deb http://archive.canonical.com/ubuntu hardy partner'
        -

        -

        Notes

        -

        This module works on Debian and Ubuntu only and requires apt-add-repository be available on destination server. To ensure this package is available use the apt module and install the python-software-properties package before using this module.

        -

        A bug in apt-add-repository always adds deb and deb-src types for repositories (see the issue on Launchpad https://bugs.launchpad.net/ubuntu/+source/software-properties/+bug/987264), if a repo doesn't have source information (eg MongoDB repo from 10gen) the system will fail while updating repositories.

        -
        -

        assemble

        -

        -New in version 0.5.

        -

        Assembles a configuration file from fragments. Often a particular program will take a single configuration file and does not support a conf.d style structure where it is easy to build up the configuration from multiple sources. Assemble will take a directory of files that have already been transferred to the system, and concatenate them together to produce a destination file. Files are assembled in string sorting order. Puppet calls this idea fragments.

        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        parameterrequireddefaultchoicescomments
        destyes
          A file to create using the concatenation of all of the source files.
          srcyes
            An already existing directory full of source files.
            backupnono
            • yes
            • no
            Create a backup file (if yes), including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.
            othersno
              all arguments accepted by the file module also work here

              Example from Ansible Playbooks

              -assemble src=/etc/someapp/fragments dest=/etc/someapp/someapp.conf
              -

              -
              -
              -

              async_status

              -

              -New in version 0.5.

              -

              This module gets the status of an asynchronous task. See: http://ansible.cc/docs/playbooks2.html#asynchronous-actions-and-polling

              - - - - - - - - - - - - - - - - - - - - - - -
              parameterrequireddefaultchoicescomments
              jidyes
                Job or task identifier
                modenostatus
                • status
                • cleanup
                if status, obtain the status; if cleanup, clean up the async job cache located in ~/.ansible_async/ for the specified job jid.

                Notes

                -

                See http://ansible.cc/docs/playbooks2.html#asynchronous-actions-and-polling

                -
                -

                authorized_key

                -

                -New in version 0.5.

                -

                Adds or removes an SSH authorized key for a user from a remote host.

                - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                parameterrequireddefaultchoicescomments
                statenopresent
                • present
                • absent
                whether the given key should or should not be in the file
                useryes
                  Name of the user who should have access to the remote host
                  keyyes
                    the SSH public key, as a string

                    Example from Ansible Playbooks

                    -authorized_key user=charlie key="ssh-dss ASDF1234L+8BTwaRYr/rycsBF1D8e5pTxEsXHQs4iq+mZdyWqlW++L6pMiam1A8yweP+rKtgjK2httVS6GigVsuWWfOd7/sdWippefq74nppVUELHPKkaIOjJNN1zUHFoL/YMwAAAEBALnAsQN10TNGsRDe5arBsW8cTOjqLyYBcIqgPYTZW8zENErFxt7ij3fW3Jh/sCpnmy8rkS7FyK8ULX0PEy/2yDx8/5rXgMIICbRH/XaBy9Ud5bRBFVkEDu/r+rXP33wFPHjWjwvHAtfci1NRBAudQI/98DbcGQw5HmE89CjgZRo5ktkC5yu/8agEPocVjdHyZr7PaHfxZGUDGKtGRL2QzRYukCmWo1cZbMBHcI5FzImvTHS9/8B3SATjXMPgbfBuEeBwuBK5EjL+CtHY5bWs9kmYjmeo0KfUMH8hY4MAXDoKhQ7DhBPIrcjS5jPtoGxIREZjba67r6/P2XKXaCZH6Fc= charlie@example.org 2011-01-17"
                    -

                    -

                    Shorthand available in Ansible 0.8 and later

                    -authorized_key user=charlie key=$FILE(/home/charlie/.ssh/id_rsa.pub)
                    -

                    -
                    -
                    -

                    command

                    -

                    The command module takes the command name followed by a list of space-delimited arguments. -The given command will be executed on all selected nodes. It will not be processed through the shell, so variables like $HOME and operations like "<", ">", "|", and "&" will not work. As such, all paths to commands must be fully qualified

                    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                    parameterrequireddefaultchoicescomments
                    createsno
                      a filename, when it already exists, this step will not be run.
                      free_formyes
                        the command module takes a free form command to run
                        chdirno
                          cd into this directory before running the command (added in Ansible 0.6)
                          removesno
                            a filename, when it does not exist, this step will not be run. (added in Ansible 0.8)

                            Example from Ansible Playbooks

                            -command /sbin/shutdown -t now
                            -

                            -

                            creates, removes, and chdir can be specified after the command. For instance, if you only want to run a command if a certain file does not exist, use this.

                            -command /usr/bin/make_database.sh arg1 arg2 creates=/path/to/database
                            -

                            -

                            Notes

                            -

                            If you want to run a command through the shell (say you are using <, >, |, etc), you actually want the shell module instead. The command module is much more secure as it's not affected by the user's environment.

                            -
                            -

                            copy

                            -

                            The copy module copies a file on the local box to remote locations.

                            - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                            parameterrequireddefaultchoicescomments
                            destyes
                              Remote absolute path where the file should be copied to.
                              srcyes
                                Local path to a file to copy to the remote server; can be absolute or relative.
                                backupnono
                                • yes
                                • no
                                Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly. (added in Ansible 0.7)
                                othersno
                                  all arguments accepted by the file module also work here

                                  Example from Ansible Playbooks

                                  -copy src=/srv/myfiles/foo.conf dest=/etc/foo.conf owner=foo group=foo mode=0644
                                  -

                                  -

                                  Copy a new ntp.conf file into place, backing up the original if it differs from the copied version

                                  -copy src=/mine/ntp.conf dest=/etc/ntp.conf owner=root group=root mode=644 backup=yes
                                  -

                                  -
                                  -
                                  -

                                  cron

                                  -

                                  -New in version 0.9.

                                  -

                                  Use this module to manage crontab entries. This module allows you to create named crontab entries, update, or delete them. -The module include one line with the description of the crontab entry “#Ansible: <name>” corresponding to the “name” passed to the module, which is used by future ansible/module calls to find/check the state.

                                  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                  parameterrequireddefaultchoicescomments
                                  nameyes
                                    Description of a crontab entry.
                                    hourno*
                                      Hour when the job should run ( 0-23, *, */2, etc )
                                      jobno
                                        The command to execute.Required if state=present.
                                        monthno*
                                          Month of the year the job should run ( 1-12, *, */2, etc )
                                          statenopresent
                                            Whether to ensure the job is present or absent.
                                            usernoroot
                                              The specific user who's crontab should be modified.
                                              backupno
                                                If set, then create a backup of the crontab before it is modified.The location of the backup is returned in the 'backup' variable by this module.
                                                dayno*
                                                  Day of the month the job should run ( 1-31, *, */2, etc )
                                                  minuteno*
                                                    Minute when the job should run ( 0-59, *, */2, etc )
                                                    weekdayno*
                                                      Day of the week that the job should run ( 0-7 for Sunday - Saturday, or mon, tue, * etc )

                                                      Ensure a job that runs at 2 and 5 exists. Creates an entry like "* 5,2 * * ls -alh > /dev/null"

                                                      -cron name="check dirs" hour="5,2" job="ls -alh > /dev/null"
                                                      -

                                                      -

                                                      Ensure an old job is no longer present. Removes any job that is preceded by "#Ansible: an old job" in the crontab

                                                      -name="an old job" cron job="/some/dir/job.sh" state=absent
                                                      -

                                                      -
                                                      -
                                                      -

                                                      debug

                                                      -

                                                      -New in version 0.8.

                                                      -

                                                      This module prints statements during execution and can be useful for debugging variables or expressions without necessarily halting the playbook. Useful for debugging together with the only_if directive. -In order to see the debug message, you need to run ansible in verbose mode (using the -v option).

                                                      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                      parameterrequireddefaultchoicescomments
                                                      msgnoHello world!
                                                        The customized message that is printed. If ommited, prints a generic message.
                                                        failnono
                                                          A boolean that indicates whether the debug module should fail or not.
                                                          rcno
                                                            The return code of the module. If fail=yes, this will default to 1.

                                                            Example that prints the loopback address and gateway for each host

                                                            -[{'local_action': 'debug msg="System $inventory_hostname has uuid $ansible_product_uuid"'}, {'only_if': "is_unset('${ansible_default_ipv4.gateway}')", 'local_action': 'debug msg="System $inventory_hostname lacks a gateway" fail=yes'}, {'only_if': "is_set('${ansible_default_ipv4.gateway}')", 'local_action': 'debug msg="System $inventory_hostname has gateway ${ansible_default_ipv4.gateway}"'}]
                                                            -

                                                            -
                                                            -
                                                            -

                                                            easy_install

                                                            -

                                                            -New in version 0.7.

                                                            -

                                                            Installs Python libraries, optionally in a virtualenv

                                                            - - - - - - - - - - - - - - - - - - - - - - -
                                                            parameterrequireddefaultchoicescomments
                                                            virtualenvno
                                                              an optional virtualenv directory path to install into. If the virtualenv does not exist, it is created automatically
                                                              nameyes
                                                                A Python library name

                                                                Examples from Ansible Playbooks

                                                                -easy_install name=pip
                                                                -

                                                                -

                                                                Install Flask (http://flask.pocoo.org/) into the specified virtualenv

                                                                -easy_install name=flask virtualenv=/webapps/myapp/venv
                                                                -

                                                                -

                                                                Notes

                                                                -

                                                                Please note that the easy_install module can only install Python libraries. Thus this module is not able to remove libraries. It is generally recommended to use the pip module which you can first install using easy_install.

                                                                -

                                                                Also note that virtualenv must be installed on the remote host if the virtualenv parameter is specified.

                                                                -
                                                                -

                                                                facter

                                                                -

                                                                -New in version 0.2.

                                                                -

                                                                Runs the facter discovery program (https://github.com/puppetlabs/facter) on the remote system, returning JSON data that can be useful for inventory purposes.

                                                                -

                                                                Example command-line invocation

                                                                -ansible  www.example.net -m facter
                                                                -

                                                                -
                                                                -
                                                                -

                                                                fail

                                                                -

                                                                -New in version 0.8.

                                                                -

                                                                This module fails the progress with a custom message. It can be useful for bailing out when a certain condition is met using only_if.

                                                                - - - - - - - - - - - - - - - - - - - - - - -
                                                                parameterrequireddefaultchoicescomments
                                                                msgno'Failed because only_if condition is true'
                                                                  The customized message used for failing execution. If ommited, fail will simple bail out with a generic message.
                                                                  rcno1
                                                                    The return code of the failure. This is currently not used by Ansible, but might be used in the future.

                                                                    Example playbook using fail and only_if together

                                                                    -action: fail msg="The system may not be provisioned according to the CMDB status." rc=100

                                                                    only_if: “’$cmdb_status’ != ‘to-be-staged’”

                                                                    -
                                                                    -
                                                                    </pre></p> -<br/>
                                                                    -
                                                                    -
                                                                    -

                                                                    fetch

                                                                    -

                                                                    -New in version 0.2.

                                                                    -

                                                                    This module works like copy, but in reverse. It is used for fetching files from remote machines and storing them locally in a file tree, organized by hostname.

                                                                    - - - - - - - - - - - - - - - - - - - - - - -
                                                                    parameterrequireddefaultchoicescomments
                                                                    destyes
                                                                      A directory to save the file into. For example, if the dest directory is /backup a src file named /etc/profile on host host.example.com, would be saved into /backup/host.example.com/etc/profile
                                                                      srcyes
                                                                        The file on the remote system to fetch. This must be a file, not a directory. Recursive fetching may be supported in a later release.

                                                                        Example from Ansible Playbooks

                                                                        -fetch src=/var/log/messages dest=/home/logtree
                                                                        -

                                                                        -
                                                                        -
                                                                        -

                                                                        file

                                                                        -

                                                                        Sets attributes of files, symlinks, and directories, or removes files/symlinks/directories. Many other modules support the same options as the file module - including copy, template, and assmeble.

                                                                        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                        parameterrequireddefaultchoicescomments
                                                                        srcno
                                                                          path of the file to link to (applies only to state=link).
                                                                          groupno
                                                                            name of the group that should own the file/directory, as would be fed to chown
                                                                            destyes
                                                                              defines the file being managed, unless when used with state=link, and then sets the destination to create a symbolic link to using src
                                                                              selevelnos0
                                                                                level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the range. _default feature works as for seuser.
                                                                                seuserno
                                                                                  user part of SELinux file context. Will default to system policy, if applicable. If set to _default, it will use the user portion of the the policy if available
                                                                                  statenofile
                                                                                  • file
                                                                                  • link
                                                                                  • directory
                                                                                  • absent
                                                                                  If directory, all immediate subdirectories will be created if they do not exist. If file, the file will NOT be created if it does not exist, see the copy or template module if you want that behavior. If link, the symbolic link will be created or changed. If absent, directories will be recursively deleted, and files or symlinks will be unlinked.
                                                                                  seroleno
                                                                                    role part of SELinux file context, _default feature works as for seuser.
                                                                                    modeno
                                                                                      mode the file or directory should be, such as 0644 as would be fed to
                                                                                      contextno
                                                                                      • default
                                                                                      accepts only default as value. This will restore a file's SELinux context in the policy. Does nothing if no default value is available.
                                                                                      ownerno
                                                                                        name of the user that should own the file/directory, as would be fed to chown
                                                                                        forceno
                                                                                          force is required when changing an existing file to a directory, or a link to a directory, and so on. Use this with caution.
                                                                                          setypeno
                                                                                            type part of SELinux file context, _default feature works as for seuser.

                                                                                            Example from Ansible Playbooks

                                                                                            -file path=/etc/foo.conf owner=foo group=foo mode=0644
                                                                                            -

                                                                                            -

                                                                                            -file src=/file/to/link/to dest=/path/to/symlink owner=foo group=foo state=link
                                                                                            -

                                                                                            -

                                                                                            Notes

                                                                                            -

                                                                                            See also copy, template, assemble

                                                                                            -
                                                                                            -

                                                                                            fireball

                                                                                            -

                                                                                            -New in version 0.9.

                                                                                            -

                                                                                            This modules launches an ephemeral fireball ZeroMQ message bus daemon on the remote node which Ansible can to communicate with nodes at high speed. -The daemon listens on a configurable port for a configurable amount of time. -Starting a new fireball as a given user terminates any existing user fireballs. -Fireball mode is AES encrypted

                                                                                            - - - - - - - - - - - - - - - - - - - - - - -
                                                                                            parameterrequireddefaultchoicescomments
                                                                                            minutesno30
                                                                                              The fireball listener daemon is started on nodes and will stay around for this number of minutes before turning itself off.
                                                                                              portno5099
                                                                                                TCP port for ZeroMQ

                                                                                                This example playbook has two plays: the first launches fireball mode on all hosts via SSH, and the second actually starts using fireball node for subsequent management over the fireball interface

                                                                                                -- hosts: devservers
                                                                                                -  gather_facts: false
                                                                                                -  connection: ssh
                                                                                                -  sudo: yes
                                                                                                -  tasks:
                                                                                                -      - action: fireball
                                                                                                -
                                                                                                -- hosts: devservers
                                                                                                -  connection: fireball
                                                                                                -  tasks:
                                                                                                -      - action: command /usr/bin/anything
                                                                                                -
                                                                                                -

                                                                                                -

                                                                                                Notes

                                                                                                -

                                                                                                See the advanced playbooks chapter for more about using fireball mode.

                                                                                                -
                                                                                                -

                                                                                                get_url

                                                                                                -

                                                                                                -New in version 0.6.

                                                                                                -

                                                                                                Downloads files from HTTP, HTTPS, or FTP to the remote server. The remote server must have direct access to the remote resource.

                                                                                                - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                parameterrequireddefaultchoicescomments
                                                                                                urlyes
                                                                                                  HTTP, HTTPS, or FTP URL
                                                                                                  destyes
                                                                                                    absolute path of where to download the file to.If dest is a directory, the basename of the file on the remote server will be used. If a directory, thirsty=yes must also be set.
                                                                                                    thirstynono
                                                                                                    • yes
                                                                                                    • no
                                                                                                    if yes, will download the file every time and replace the file if the contents change. if no, the file will only be downloaded if the destination does not exist. Generally should be yes only for small local files. prior to 0.6, acts if yes by default. (added in Ansible 0.7)
                                                                                                    othersno
                                                                                                      all arguments accepted by the file module also work here

                                                                                                      Example from Ansible Playbooks

                                                                                                      -get_url url=http://example.com/path/file.conf dest=/etc/foo.conf mode=0440
                                                                                                      -

                                                                                                      -

                                                                                                      Notes

                                                                                                      -

                                                                                                      This module doesn't yet support configuration for proxies or passwords.

                                                                                                      -
                                                                                                      -

                                                                                                      git

                                                                                                      -

                                                                                                      -New in version 0.0.1.

                                                                                                      -

                                                                                                      Manage git checkouts of repositories to deploy files or software.

                                                                                                      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                      parameterrequireddefaultchoicescomments
                                                                                                      repoyes
                                                                                                        git, ssh, or http protocol address of the git repository.
                                                                                                        destyes
                                                                                                          Absolute path of where the repository should be checked out to.
                                                                                                          versionnoHEAD
                                                                                                            What version of the repository to check out. This can be the git SHA, the literal string HEAD, branch name, or a tag name.
                                                                                                            forcenoyes
                                                                                                            • True
                                                                                                            • False
                                                                                                            (New in 0.7) If yes, any modified files in the working repository will be discarded. Prior to 0.7, this was always 'yes' and could not be disabled.
                                                                                                            remotenoorigin
                                                                                                              Name of the remote branch.

                                                                                                              Example git checkout from Ansible Playbooks

                                                                                                              -git repo=git://foosball.example.org/path/to/repo.git dest=/srv/checkout version=release-0.22
                                                                                                              -

                                                                                                              -
                                                                                                              -
                                                                                                              -

                                                                                                              group

                                                                                                              -

                                                                                                              -New in version 0.0.2.

                                                                                                              -

                                                                                                              Manage presence of groups on a host.

                                                                                                              - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                              parameterrequireddefaultchoicescomments
                                                                                                              statenopresent
                                                                                                              • present
                                                                                                              • absent
                                                                                                              Whether the group should be present or not on the remote host.
                                                                                                              gidno
                                                                                                                Optional GID to set for the group.
                                                                                                                nameyes
                                                                                                                  Name of the group to manage.
                                                                                                                  systemnono
                                                                                                                  • True
                                                                                                                  • False
                                                                                                                  If yes, indicates that the group created is a system group.

                                                                                                                  Example group command from Ansible Playbooks

                                                                                                                  -group name=somegroup state=present
                                                                                                                  -

                                                                                                                  -
                                                                                                                  -
                                                                                                                  -

                                                                                                                  hpilo_boot

                                                                                                                  -

                                                                                                                  -New in version 0.8.

                                                                                                                  -

                                                                                                                  This module boots a system through its HP iLO interface. The boot media can be one of: cdrom, floppy, hdd, network or usb. -This module requires the hpilo python module.

                                                                                                                  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                  parameterrequireddefaultchoicescomments
                                                                                                                  forceno
                                                                                                                  • yes
                                                                                                                  • no
                                                                                                                  Whether to force a reboot (even when the system is already booted)
                                                                                                                  medianonetwork
                                                                                                                  • cdrom
                                                                                                                  • floppy
                                                                                                                  • hdd
                                                                                                                  • network
                                                                                                                  • normal
                                                                                                                  • usb
                                                                                                                  The boot media to boot the system from
                                                                                                                  imageno
                                                                                                                    The URL of a cdrom, floppy or usb boot media image. protocol://username:password@hostname:port/filenameprotocol is either http or httpsusername:password is optionalport is optional
                                                                                                                    hostyes
                                                                                                                      The HP iLO hostname/address that is linked to the physical system.
                                                                                                                      stateyesboot_once
                                                                                                                      • boot_always
                                                                                                                      • boot_once
                                                                                                                      • connect
                                                                                                                      • disconnect
                                                                                                                      • no_boot
                                                                                                                      The state of the boot media.no_boot: Do not boot from the deviceboot_once: Boot from the device once and then notthereafterboot_always: Boot from the device each time the serveris rebootedconnect: Connect the virtual media device and set to boot_alwaysdisconnect: Disconnects the virtual media device and set to no_boot
                                                                                                                      loginnoAdministrator
                                                                                                                        The login name to authenticate to the HP iLO interface.
                                                                                                                        passwordnoadmin
                                                                                                                          The password to authenticate to the HP iLO interface.
                                                                                                                          matchno
                                                                                                                            An optional string to match against the iLO server name.This is a safety measure to prevent accidentally using the wrong HP iLO interface with dire consequences.

                                                                                                                            Task to boot a system using an ISO from an HP iLO interface only if the system is an HP server

                                                                                                                            -local_action: hpilo_boot host=$ilo_address login=$ilo_login password=$ilo_password match=$inventory_hostname_short media=cdrom image=$iso_url

                                                                                                                            only_if: “’$cmdb_hwmodel’.startswith(‘HP ‘)

                                                                                                                            -
                                                                                                                            -
                                                                                                                            </pre></p> -<br/>
                                                                                                                            -

                                                                                                                            Notes

                                                                                                                            -

                                                                                                                            To use a USB key image you need to specify floppy as boot media.

                                                                                                                            -

                                                                                                                            This module ought to be run from a system that can access the HP iLO interface directly, either by using local_action or using delegate_to.

                                                                                                                            -
                                                                                                                            -

                                                                                                                            hpilo_facts

                                                                                                                            -

                                                                                                                            -New in version 0.8.

                                                                                                                            -

                                                                                                                            This module gathers facts for a specific system using its HP iLO interface. These facts include hardware and network related information useful for provisioning (e.g. macaddress, uuid). -This module requires the hpilo python module.

                                                                                                                            - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                            parameterrequireddefaultchoicescomments
                                                                                                                            hostyes
                                                                                                                              The HP iLO hostname/address that is linked to the physical system.
                                                                                                                              passwordnoadmin
                                                                                                                                The password to authenticate to the HP iLO interface.
                                                                                                                                loginnoAdministrator
                                                                                                                                  The login name to authenticate to the HP iLO interface.
                                                                                                                                  matchno
                                                                                                                                    An optional string to match against the iLO server name.This is a safety measure to prevent accidentally using the wrong HP iLO interface with dire consequences.

                                                                                                                                    Task to gather facts from a HP iLO interface only if the system is an HP server

                                                                                                                                    -local_action: hpilo_facts host=$ilo_address login=$ilo_login password=$ilo_password match=$inventory_hostname_short

                                                                                                                                    only_if: “’$cmdb_hwmodel’.startswith(‘HP ‘)

                                                                                                                                    -
                                                                                                                                    -
                                                                                                                                    -
                                                                                                                                    </pre></p> -<p>Typical output of HP iLO_facts for a physical system</p> <p><pre> -- hw_bios_date: “05/05/2011”
                                                                                                                                    -

                                                                                                                                    hw_bios_version: “P68” -hw_eth0: -- macaddress: “00:11:22:33:44:55”

                                                                                                                                    -
                                                                                                                                    -
                                                                                                                                    macaddress_dash: “00-11-22-33-44-55”
                                                                                                                                    -

                                                                                                                                    hw_eth1: -- macaddress: “00:11:22:33:44:57”

                                                                                                                                    -
                                                                                                                                    -
                                                                                                                                    macaddress_dash: “00-11-22-33-44-57”
                                                                                                                                    -

                                                                                                                                    hw_eth2: -- macaddress: “00:11:22:33:44:5A”

                                                                                                                                    -
                                                                                                                                    -
                                                                                                                                    macaddress_dash: “00-11-22-33-44-5A”
                                                                                                                                    -

                                                                                                                                    hw_eth3: -- macaddress: “00:11:22:33:44:5C”

                                                                                                                                    -
                                                                                                                                    -
                                                                                                                                    macaddress_dash: “00-11-22-33-44-5C”
                                                                                                                                    -

                                                                                                                                    hw_eth_ilo: -- macaddress: “00:11:22:33:44:BA”

                                                                                                                                    -
                                                                                                                                    -
                                                                                                                                    macaddress_dash: “00-11-22-33-44-BA”
                                                                                                                                    -

                                                                                                                                    hw_product_name: “ProLiant DL360 G7” -hw_product_uuid: “ef50bac8-2845-40ff-81d9-675315501dac” -hw_system_serial: “ABC12345D6” -hw_uuid: “123456ABC78901D2”

                                                                                                                                    -
                                                                                                                                    -
                                                                                                                                    </pre></p> -<br/>
                                                                                                                                    -
                                                                                                                                    -

                                                                                                                                    Notes

                                                                                                                                    -

                                                                                                                                    This module ought to be run from a system that can access the HP iLO interface directly, either by using local_action or using delegate_to.

                                                                                                                                    -
                                                                                                                                    -

                                                                                                                                    ini_file

                                                                                                                                    -

                                                                                                                                    -New in version 0.9.

                                                                                                                                    -

                                                                                                                                    Manage (add, remove, change) individual settings in an INI-style file without having to manage the file as a whole with, say, template or assemble. Adds missing sections if they don’t exist.

                                                                                                                                    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                    parameterrequireddefaultchoicescomments
                                                                                                                                    optionno
                                                                                                                                      if set (required for changing a value), this is the name of the option.May be omitted if adding/removing a whole section.
                                                                                                                                      othersno
                                                                                                                                        all arguments accepted by the file module also work here
                                                                                                                                        destyes
                                                                                                                                          Path to the INI-style file; this file is created if required
                                                                                                                                          sectionyes
                                                                                                                                            Section name in INI file. This is added if state=present automatically when a single value is being set.
                                                                                                                                            backupno
                                                                                                                                            • yes
                                                                                                                                            • no
                                                                                                                                            Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.
                                                                                                                                            valueno
                                                                                                                                              the string value to be associated with an option. May be omitted when removing an option.

                                                                                                                                              Ensure fav=lemonade is in section [drinks] in said file

                                                                                                                                              -ini_file dest=/etc/conf section=drinks option=fav value=lemonade mode=0600 backup=true
                                                                                                                                              -

                                                                                                                                              -

                                                                                                                                              -ini_file dest=/etc/anotherconf
                                                                                                                                              -     section=drinks
                                                                                                                                              -     option=temperature
                                                                                                                                              -     value=cold
                                                                                                                                              -     backup=true
                                                                                                                                              -
                                                                                                                                              -

                                                                                                                                              -

                                                                                                                                              Notes

                                                                                                                                              -

                                                                                                                                              While it is possible to add an option without specifying a value, this makes no sense.

                                                                                                                                              -
                                                                                                                                              -

                                                                                                                                              lineinfile

                                                                                                                                              -

                                                                                                                                              -New in version 0.7.

                                                                                                                                              -

                                                                                                                                              This module will search a file for a line, and ensure that it is present or absent. -This is primarily useful when you want to change a single line in a file only. For other cases, see the copy or template modules.

                                                                                                                                              - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                              parameterrequireddefaultchoicescomments
                                                                                                                                              insertafternoEOF
                                                                                                                                              • BOF
                                                                                                                                              • EOF
                                                                                                                                              Used with state=present. If specified, the line will be inserted after the specified regular expression. Two special values are available; BOF for inserting the line at the beginning of the file, and EOF for inserting the line at the end of the file.
                                                                                                                                              statenopresent
                                                                                                                                              • present
                                                                                                                                              • absent
                                                                                                                                              Whether the line should be there or not.
                                                                                                                                              destyes
                                                                                                                                                The file to modify
                                                                                                                                                regexpyes
                                                                                                                                                  The regular expression to look for in the file. For state=present, the pattern to replace. For state=absent, the pattern of the line to remove.
                                                                                                                                                  lineno
                                                                                                                                                    Required for state=present. The line to insert/replace into the file. Must match the value given to regexp.
                                                                                                                                                    backupno
                                                                                                                                                      Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.

                                                                                                                                                      -lineinfile dest=/etc/selinux/config regexp=^SELINUX= line=SELINUX=disabled
                                                                                                                                                      -

                                                                                                                                                      -

                                                                                                                                                      -lineinfile dest=/etc/sudoers state=absent regexp="^%wheel"
                                                                                                                                                      -

                                                                                                                                                      -
                                                                                                                                                      -
                                                                                                                                                      -

                                                                                                                                                      mount

                                                                                                                                                      -

                                                                                                                                                      -New in version 0.6.

                                                                                                                                                      -

                                                                                                                                                      This module controls active and configured mount points in /etc/fstab.

                                                                                                                                                      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                      parameterrequireddefaultchoicescomments
                                                                                                                                                      srcyes
                                                                                                                                                        device to be mounted on name.
                                                                                                                                                        stateyes
                                                                                                                                                        • present
                                                                                                                                                        • absent
                                                                                                                                                        • mounted
                                                                                                                                                        • unmounted
                                                                                                                                                        If mounted or unmounted, the device will be actively mounted or unmounted as well as just configured in fstab. absent and present only deal with fstab.
                                                                                                                                                        nameyes
                                                                                                                                                          path to the mount point, eg: /mnt/files
                                                                                                                                                          dumpno
                                                                                                                                                            dump (see fstab(8))
                                                                                                                                                            passnono
                                                                                                                                                              passno (see fstab(8))
                                                                                                                                                              optsno
                                                                                                                                                                mount options (see fstab(8))
                                                                                                                                                                fstypeyes
                                                                                                                                                                  file-system type

                                                                                                                                                                  Mount DVD read-only

                                                                                                                                                                  -mount name=/mnt/dvd src=/dev/sr0 fstype=iso9660 opts=ro
                                                                                                                                                                  -

                                                                                                                                                                  -
                                                                                                                                                                  -
                                                                                                                                                                  -

                                                                                                                                                                  mysql_db

                                                                                                                                                                  -

                                                                                                                                                                  -New in version 0.6.

                                                                                                                                                                  -

                                                                                                                                                                  Add or remove MySQL databases from a remote host.

                                                                                                                                                                  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                  parameterrequireddefaultchoicescomments
                                                                                                                                                                  statenopresent
                                                                                                                                                                  • present
                                                                                                                                                                  • absent
                                                                                                                                                                  The database state
                                                                                                                                                                  nameyes
                                                                                                                                                                    name of the database to add or remove
                                                                                                                                                                    encodingno
                                                                                                                                                                      Encoding mode
                                                                                                                                                                      collationno
                                                                                                                                                                        Collation mode
                                                                                                                                                                        login_userno
                                                                                                                                                                          The username used to authenticate with
                                                                                                                                                                          login_hostnolocalhost
                                                                                                                                                                            Host running the database
                                                                                                                                                                            login_passwordno
                                                                                                                                                                              The password used to authenticate with

                                                                                                                                                                              Create a new database with name 'bobdata'

                                                                                                                                                                              -mysql_db db=bobdata state=present
                                                                                                                                                                              -

                                                                                                                                                                              -

                                                                                                                                                                              Notes

                                                                                                                                                                              -

                                                                                                                                                                              Requires the MySQLdb Python package on the remote host. For Ubuntu, this is as easy as apt-get install python-mysqldb.

                                                                                                                                                                              -

                                                                                                                                                                              Both login_password and login_username are required when you are passing credentials. If none are present, the module will attempt to read the credentials from ~/.my.cnf, and finally fall back to using the MySQL default login of 'root' with no password.

                                                                                                                                                                              -
                                                                                                                                                                              -

                                                                                                                                                                              mysql_user

                                                                                                                                                                              -

                                                                                                                                                                              -New in version 0.6.

                                                                                                                                                                              -

                                                                                                                                                                              Adds or removes a user from a MySQL database.

                                                                                                                                                                              - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                              parameterrequireddefaultchoicescomments
                                                                                                                                                                              nameyes
                                                                                                                                                                                name of the user (role) to add or remove
                                                                                                                                                                                login_userno
                                                                                                                                                                                  The username used to authenticate with
                                                                                                                                                                                  login_hostnolocalhost
                                                                                                                                                                                    Host running the database
                                                                                                                                                                                    hostnolocalhost
                                                                                                                                                                                      the 'host' part of the MySQL username
                                                                                                                                                                                      statenopresent
                                                                                                                                                                                      • present
                                                                                                                                                                                      • absent
                                                                                                                                                                                      The database state
                                                                                                                                                                                      login_passwordno
                                                                                                                                                                                        The password used to authenticate with
                                                                                                                                                                                        passwordno
                                                                                                                                                                                          set the user's password
                                                                                                                                                                                          privno
                                                                                                                                                                                            MySQL privileges string in the format: db.table:priv1,priv2

                                                                                                                                                                                            Create database user with name 'bob' and password '12345' with all database privileges

                                                                                                                                                                                            -mysql_user name=bob password=12345 priv=*.*:ALL state=present
                                                                                                                                                                                            -

                                                                                                                                                                                            -

                                                                                                                                                                                            Ensure no user named 'sally' exists, also passing in the auth credentials.

                                                                                                                                                                                            -mysql_user login_user=root login_password=123456 name=sally state=absent
                                                                                                                                                                                            -

                                                                                                                                                                                            -

                                                                                                                                                                                            Example privileges string format

                                                                                                                                                                                            -mydb.*:INSERT,UPDATE/anotherdb.*:SELECT/yetanotherdb.*:ALL
                                                                                                                                                                                            -

                                                                                                                                                                                            -

                                                                                                                                                                                            Notes

                                                                                                                                                                                            -

                                                                                                                                                                                            Requires the MySQLdb Python package on the remote host. For Ubuntu, this is as easy as apt-get install python-mysqldb.

                                                                                                                                                                                            -

                                                                                                                                                                                            Both login_password and login_username are required when you are passing credentials. If none are present, the module will attempt to read the credentials from ~/.my.cnf, and finally fall back to using the MySQL default login of 'root' with no password.

                                                                                                                                                                                            -
                                                                                                                                                                                            -

                                                                                                                                                                                            nagios

                                                                                                                                                                                            -

                                                                                                                                                                                            -New in version 0.7.

                                                                                                                                                                                            -

                                                                                                                                                                                            The nagios module has two basic functions: scheduling downtime and toggling alerts for services or hosts. -All actions require the host parameter to be given explicitly. In playbooks you can use the $inventory_hostname variable to refer to the host the playbook is currently running on. -You can specify multiple services at once by separating them with commas, .e.g., services=httpd,nfs,puppet. -When specifying what service to handle there is a special service value, host, which will handle alerts/downtime for the host itself, e.g., service=host. This keyword may not be given with other services at the same time. Setting alerts/downtime for a host does not affect alerts/downtime for any of the services running on it. -When using the nagios module you will need to specify your nagios server using the delegate_to parameter.

                                                                                                                                                                                            - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                            parameterrequireddefaultchoicescomments
                                                                                                                                                                                            actionyes
                                                                                                                                                                                            • downtime
                                                                                                                                                                                            • enable_alerts
                                                                                                                                                                                            • disable_alerts
                                                                                                                                                                                            • silence
                                                                                                                                                                                            • unsilence
                                                                                                                                                                                            Action to take.
                                                                                                                                                                                            hostyes
                                                                                                                                                                                              Host to operate on in Nagios.
                                                                                                                                                                                              authornoAnsible
                                                                                                                                                                                                Author to leave downtime comments as. - Only useable with the downtime action.
                                                                                                                                                                                                servicesyes
                                                                                                                                                                                                  What to manage downtime/alerts for. Separate multiple services with commas.service is an alias for services.Required option when using the downtime, enable_alerts, and disable_alerts actions.
                                                                                                                                                                                                  minutesno30
                                                                                                                                                                                                    Minutes to schedule downtime for.Only useable with the downtime action.
                                                                                                                                                                                                    cmdfilenoauto-detected
                                                                                                                                                                                                      Path to the nagios command file (FIFO pipe).Only required if auto-detection fails.

                                                                                                                                                                                                      set 30 minutes of apache downtime

                                                                                                                                                                                                      -nagios action=downtime minutes=30 service=httpd host=$inventory_hostname
                                                                                                                                                                                                      -

                                                                                                                                                                                                      -

                                                                                                                                                                                                      schedule an hour of HOST downtime

                                                                                                                                                                                                      -nagios action=downtime minutes=60 service=host host=$inventory_hostname
                                                                                                                                                                                                      -

                                                                                                                                                                                                      -

                                                                                                                                                                                                      schedule downtime for a few services

                                                                                                                                                                                                      -nagios action=downtime services=frob,foobar,qeuz host=$inventory_hostname
                                                                                                                                                                                                      -

                                                                                                                                                                                                      -

                                                                                                                                                                                                      enable SMART disk alerts

                                                                                                                                                                                                      -nagios action=enable_alerts service=smart host=$inventory_hostname
                                                                                                                                                                                                      -

                                                                                                                                                                                                      -

                                                                                                                                                                                                      two services at once: disable httpd and nfs alerts

                                                                                                                                                                                                      -nagios action=disable_alerts service=httpd,nfs host=$inventory_hostname
                                                                                                                                                                                                      -

                                                                                                                                                                                                      -

                                                                                                                                                                                                      disable HOST alerts

                                                                                                                                                                                                      -nagios action=disable_alerts service=host host=$inventory_hostname
                                                                                                                                                                                                      -

                                                                                                                                                                                                      -

                                                                                                                                                                                                      silence ALL alerts

                                                                                                                                                                                                      -nagios action=silence host=$inventory_hostname
                                                                                                                                                                                                      -

                                                                                                                                                                                                      -

                                                                                                                                                                                                      unsilence all alerts

                                                                                                                                                                                                      -nagios action=unsilence host=$inventory_hostname
                                                                                                                                                                                                      -

                                                                                                                                                                                                      -
                                                                                                                                                                                                      -
                                                                                                                                                                                                      -

                                                                                                                                                                                                      ohai

                                                                                                                                                                                                      -

                                                                                                                                                                                                      -New in version 0.6.

                                                                                                                                                                                                      -

                                                                                                                                                                                                      Similar to the facter module, this runs the ohai discovery program (http://wiki.opscode.com/display/chef/Ohai) on the remote host and returns JSON inventory data. Ohai data is a bit more verbose and nested than facter.

                                                                                                                                                                                                      -

                                                                                                                                                                                                      Retrieve ohai data from all Web servers and store in one-file per host

                                                                                                                                                                                                      -ansible webservers -m ohai --tree=/tmp/ohaidata
                                                                                                                                                                                                      -

                                                                                                                                                                                                      -
                                                                                                                                                                                                      -
                                                                                                                                                                                                      -

                                                                                                                                                                                                      pause

                                                                                                                                                                                                      -

                                                                                                                                                                                                      -New in version 0.8.

                                                                                                                                                                                                      -

                                                                                                                                                                                                      Pauses playbook execution for a set amount of time, or until a prompt is acknowledged. All parameters are optional. The default behavior is to pause with a prompt. -You can use ctrl+c if you wish to advance a pause earlier than it is set to expire or if you need to abort a playbook run entirely. To continue early: press ctrl+c and then c. To abort a playbook: press ctrl+c and then a. -The pause module integrates into async/parallelized playbooks without any special considerations (see also: Rolling Updates). When using pauses with the serial playbook parameter (as in rolling updates) you are only prompted once for the current group of hosts.

                                                                                                                                                                                                      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                      parameterrequireddefaultchoicescomments
                                                                                                                                                                                                      secondsno
                                                                                                                                                                                                        Number of minutes to pause for.
                                                                                                                                                                                                        minutesno
                                                                                                                                                                                                          Number of minutes to pause for.
                                                                                                                                                                                                          promptno
                                                                                                                                                                                                            Optional text to use for the prompt message.

                                                                                                                                                                                                            Pause for 5 minutes to build app cache.

                                                                                                                                                                                                            -pause minutes=5
                                                                                                                                                                                                            -

                                                                                                                                                                                                            -

                                                                                                                                                                                                            Pause until you can verify updates to an application were successful.

                                                                                                                                                                                                            -pause
                                                                                                                                                                                                            -

                                                                                                                                                                                                            -

                                                                                                                                                                                                            A helpful reminder of what to look out for post-update.

                                                                                                                                                                                                            -pause prompt=Make sure org.foo.FooOverload exception is not present
                                                                                                                                                                                                            -

                                                                                                                                                                                                            -
                                                                                                                                                                                                            -
                                                                                                                                                                                                            -

                                                                                                                                                                                                            ping

                                                                                                                                                                                                            -

                                                                                                                                                                                                            A trivial test module, this module always returns ‘pong’ on successful contact. It does not make sense in playbooks, but is useful from /usr/bin/ansible

                                                                                                                                                                                                            -

                                                                                                                                                                                                            Test 'webservers' status

                                                                                                                                                                                                            -ansible webservers -m ping
                                                                                                                                                                                                            -

                                                                                                                                                                                                            -
                                                                                                                                                                                                            -
                                                                                                                                                                                                            -

                                                                                                                                                                                                            pip

                                                                                                                                                                                                            -

                                                                                                                                                                                                            -New in version 0.7.

                                                                                                                                                                                                            -

                                                                                                                                                                                                            Manage Python library dependencies.

                                                                                                                                                                                                            - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                            parameterrequireddefaultchoicescomments
                                                                                                                                                                                                            virtualenvno
                                                                                                                                                                                                              An optional path to a virtualenv directory to install into
                                                                                                                                                                                                              statenopresent
                                                                                                                                                                                                              • present
                                                                                                                                                                                                              • absent
                                                                                                                                                                                                              • latest
                                                                                                                                                                                                              The state of module
                                                                                                                                                                                                              versionno
                                                                                                                                                                                                                The version number to install of the Python library specified in the 'name' parameter
                                                                                                                                                                                                                requirementsno
                                                                                                                                                                                                                  The path to a pip requirements file
                                                                                                                                                                                                                  nameyes
                                                                                                                                                                                                                    The name of a Python library to install

                                                                                                                                                                                                                    Install flask python package.

                                                                                                                                                                                                                    -pip name=flask
                                                                                                                                                                                                                    -

                                                                                                                                                                                                                    -

                                                                                                                                                                                                                    Install flask python package on version 0.8.

                                                                                                                                                                                                                    -pip name=flask version=0.8
                                                                                                                                                                                                                    -

                                                                                                                                                                                                                    -

                                                                                                                                                                                                                    Install Flask (http://flask.pocoo.org/) into the specified virtualenv

                                                                                                                                                                                                                    -pip name=flask virtualenv=/srv/webapps/my_app/venv
                                                                                                                                                                                                                    -

                                                                                                                                                                                                                    -

                                                                                                                                                                                                                    Install specified python requirements.

                                                                                                                                                                                                                    -pip requirements=/srv/webapps/my_app/src/requirements.txt
                                                                                                                                                                                                                    -

                                                                                                                                                                                                                    -

                                                                                                                                                                                                                    Install specified python requirements in indicated virtualenv.

                                                                                                                                                                                                                    -pip requirements=/srv/webapps/my_app/src/requirements.txt virtualenv=/srv/webapps/my_app/venv
                                                                                                                                                                                                                    -

                                                                                                                                                                                                                    -

                                                                                                                                                                                                                    Notes

                                                                                                                                                                                                                    -

                                                                                                                                                                                                                    Please note that http://www.virtualenv.org/, virtualenv must be installed on the remote host if the virtualenv parameter is specified.

                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    -

                                                                                                                                                                                                                    postgresql_db

                                                                                                                                                                                                                    -

                                                                                                                                                                                                                    -New in version 0.6.

                                                                                                                                                                                                                    -

                                                                                                                                                                                                                    Add or remove PostgreSQL databases from a remote host.

                                                                                                                                                                                                                    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                    parameterrequireddefaultchoicescomments
                                                                                                                                                                                                                    statenopresent
                                                                                                                                                                                                                    • present
                                                                                                                                                                                                                    • absent
                                                                                                                                                                                                                    The database state
                                                                                                                                                                                                                    nameyes
                                                                                                                                                                                                                      name of the database to add or remove
                                                                                                                                                                                                                      login_passwordno
                                                                                                                                                                                                                        The password used to authenticate with
                                                                                                                                                                                                                        ownerno
                                                                                                                                                                                                                          Name of the role to set as owner of the database
                                                                                                                                                                                                                          login_userno
                                                                                                                                                                                                                            The username used to authenticate with
                                                                                                                                                                                                                            login_hostnolocalhost
                                                                                                                                                                                                                              Host running the database

                                                                                                                                                                                                                              Create a new database with name 'acme'

                                                                                                                                                                                                                              -postgresql_db db=acme
                                                                                                                                                                                                                              -

                                                                                                                                                                                                                              -

                                                                                                                                                                                                                              Notes

                                                                                                                                                                                                                              -

                                                                                                                                                                                                                              The default authentication assumes that you are either logging in as or sudo'ing to the postgres account on the host.

                                                                                                                                                                                                                              -

                                                                                                                                                                                                                              This module uses psycopg2, a Python PostgreSQL database adapter. You must ensure that psycopg2 is installed on the host before using this module. If the remote host is the PostgreSQL server (which is the default case), then PostgreSQL must also be installed on the remote host. For Ubuntu-based systems, install the postgresql, libpq-dev, and python-psycopg2 packages on the remote host before using this module.

                                                                                                                                                                                                                              -
                                                                                                                                                                                                                              -

                                                                                                                                                                                                                              postgresql_user

                                                                                                                                                                                                                              -

                                                                                                                                                                                                                              -New in version 0.6.

                                                                                                                                                                                                                              -

                                                                                                                                                                                                                              Add or remove PostgreSQL users (roles) from a remote host and, optionally, grant the users access to an existing database or tables. -The fundamental function of the module is to create, or delete, roles from a PostgreSQL cluster. Privilege assignment, or removal, is an optional step, which works on one database at a time. This allows for the module to be called several times in the same module to modify the permissions on different databases, or to grant permissions to already existing users. -A user cannot be removed untill all the privileges have been stripped from the user. In such situation, if the module tries to remove the user it will fail. To avoid this from happening the fail_on_user option signals the module to try to remove the user, but if not possible keep going; the module will report if changes happened and separately if the user was removed or not.

                                                                                                                                                                                                                              - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                              parameterrequireddefaultchoicescomments
                                                                                                                                                                                                                              nameyes
                                                                                                                                                                                                                                name of the user (role) to add or remove
                                                                                                                                                                                                                                login_usernopostgres
                                                                                                                                                                                                                                  User (role) used to authenticate with PostgreSQL
                                                                                                                                                                                                                                  login_hostnolocalhost
                                                                                                                                                                                                                                    Host running PostgreSQL.
                                                                                                                                                                                                                                    dbno
                                                                                                                                                                                                                                      name of database where permissions will be granted
                                                                                                                                                                                                                                      statenopresent
                                                                                                                                                                                                                                      • present
                                                                                                                                                                                                                                      • absent
                                                                                                                                                                                                                                      The database state
                                                                                                                                                                                                                                      login_passwordno
                                                                                                                                                                                                                                        Password used to authenticate with PostgreSQL
                                                                                                                                                                                                                                        passwordyes
                                                                                                                                                                                                                                          set the user's password
                                                                                                                                                                                                                                          fail_on_usernoTrue
                                                                                                                                                                                                                                          • yes
                                                                                                                                                                                                                                          • no
                                                                                                                                                                                                                                          if yes, fail when user can't be removed. Otherwise just log and continue
                                                                                                                                                                                                                                          privno
                                                                                                                                                                                                                                            PostgreSQL privileges string in the format: table:priv1,priv2

                                                                                                                                                                                                                                            Create django user and grant access to database and products table

                                                                                                                                                                                                                                            -postgresql_user db=acme user=django password=ceec4eif7ya priv=CONNECT/products:ALL
                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            Remove test user privileges from acme

                                                                                                                                                                                                                                            -postgresql_user db=acme user=test priv=ALL/products:ALL state=absent fail_on_user=no
                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            Remove test user from test database and the cluster

                                                                                                                                                                                                                                            -postgresql_user db=test user=test priv=ALL state=absent
                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            Example privileges string format

                                                                                                                                                                                                                                            -INSERT,UPDATE/table:SELECT/anothertable:ALL
                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            Notes

                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            The default authentication assumes that you are either logging in as or sudo'ing to the postgres account on the host.

                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            This module uses psycopg2, a Python PostgreSQL database adapter. You must ensure that psycopg2 is installed on the host before using this module. If the remote host is the PostgreSQL server (which is the default case), then PostgreSQL must also be installed on the remote host. For Ubuntu-based systems, install the postgresql, libpq-dev, and python-psycopg2 packages on the remote host before using this module.

                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            raw

                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            Executes a low-down and dirty SSH command, not going through the module subsystem. This is useful and should only be done in two cases. The first case is installing python-simplejson on older (Python 2.4 and before) hosts that need it as a dependency to run modules, since nearly all core modules require it. Another is speaking to any devices such as routers that do not have any Python installed. In any other case, using the shell or command module is much more appropriate. Arguments given to raw are run directly through the configured remote shell and only output is returned. There is no error detection or change handler support for this module

                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            Example from /usr/bin/ansible to bootstrap a legacy python 2.4 host

                                                                                                                                                                                                                                            -ansible newhost.example.com -m raw -a "yum -y install python-simplejson"
                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            seboolean

                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            -New in version 0.7.

                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                            Toggles SELinux booleans.

                                                                                                                                                                                                                                            - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                            parameterrequireddefaultchoicescomments
                                                                                                                                                                                                                                            stateyes
                                                                                                                                                                                                                                            • true
                                                                                                                                                                                                                                            • false
                                                                                                                                                                                                                                            Desired boolean value
                                                                                                                                                                                                                                            nameyes
                                                                                                                                                                                                                                              Name of the boolean to configure
                                                                                                                                                                                                                                              persistentno
                                                                                                                                                                                                                                              • yes
                                                                                                                                                                                                                                              • no
                                                                                                                                                                                                                                              Set to 'yes' if the boolean setting should survive a reboot

                                                                                                                                                                                                                                              Set httpd_can_network_connect SELinux flag to true and persistent

                                                                                                                                                                                                                                              -seboolean name=httpd_can_network_connect state=true persistent=yes
                                                                                                                                                                                                                                              -

                                                                                                                                                                                                                                              -

                                                                                                                                                                                                                                              Notes

                                                                                                                                                                                                                                              -

                                                                                                                                                                                                                                              Not tested on any debian based system

                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              -

                                                                                                                                                                                                                                              selinux

                                                                                                                                                                                                                                              -

                                                                                                                                                                                                                                              -New in version 0.7.

                                                                                                                                                                                                                                              -

                                                                                                                                                                                                                                              Configures the SELinux mode and policy. A reboot may be required after usage. Ansible will not issue this reboot but will let you know when it is required.

                                                                                                                                                                                                                                              - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                              parameterrequireddefaultchoicescomments
                                                                                                                                                                                                                                              policyyes
                                                                                                                                                                                                                                                name of the SELinux policy to use (example: 'targeted')
                                                                                                                                                                                                                                                stateyes
                                                                                                                                                                                                                                                • enforcing
                                                                                                                                                                                                                                                • permissive
                                                                                                                                                                                                                                                • disabled
                                                                                                                                                                                                                                                The SELinux mode
                                                                                                                                                                                                                                                confno/etc/selinux/config
                                                                                                                                                                                                                                                  path to the SELinux configuration file, if non-standard

                                                                                                                                                                                                                                                  -selinux policy=targeted state=enforcing
                                                                                                                                                                                                                                                  -

                                                                                                                                                                                                                                                  -

                                                                                                                                                                                                                                                  -selinux policy=targeted state=disabled
                                                                                                                                                                                                                                                  -

                                                                                                                                                                                                                                                  -

                                                                                                                                                                                                                                                  Notes

                                                                                                                                                                                                                                                  -

                                                                                                                                                                                                                                                  Not tested on any debian based system

                                                                                                                                                                                                                                                  -
                                                                                                                                                                                                                                                  -

                                                                                                                                                                                                                                                  service

                                                                                                                                                                                                                                                  -

                                                                                                                                                                                                                                                  -New in version 0.1.

                                                                                                                                                                                                                                                  -

                                                                                                                                                                                                                                                  Controls services on remote hosts.

                                                                                                                                                                                                                                                  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                  parameterrequireddefaultchoicescomments
                                                                                                                                                                                                                                                  patternno
                                                                                                                                                                                                                                                    If the service does not respond to the status command, name a substring to look for as would be found in the output of the ps command as a stand-in for a status result. If the string is found, the service will be assumed to be running. (added in Ansible 0.7)
                                                                                                                                                                                                                                                    stateno
                                                                                                                                                                                                                                                    • running
                                                                                                                                                                                                                                                    • started
                                                                                                                                                                                                                                                    • stopped
                                                                                                                                                                                                                                                    • restarted
                                                                                                                                                                                                                                                    • reloaded
                                                                                                                                                                                                                                                    started, stopped, reloaded, restarted. Started/stopped are idempotent actions that will not run commands unless necessary. restarted will always bounce the service. reloaded will always reload.
                                                                                                                                                                                                                                                    enabledno
                                                                                                                                                                                                                                                    • yes
                                                                                                                                                                                                                                                    • no
                                                                                                                                                                                                                                                    Whether the service should start on boot.
                                                                                                                                                                                                                                                    nameyes
                                                                                                                                                                                                                                                      Name of the service.

                                                                                                                                                                                                                                                      Example action from Ansible Playbooks

                                                                                                                                                                                                                                                      -service name=httpd state=started
                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      Example action from Ansible Playbooks

                                                                                                                                                                                                                                                      -service name=httpd state=stopped
                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      Example action from Ansible Playbooks

                                                                                                                                                                                                                                                      -service name=httpd state=restarted
                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      Example action from Ansible Playbooks

                                                                                                                                                                                                                                                      -service name=httpd state=reloaded
                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      Example action from Ansible Playbooks

                                                                                                                                                                                                                                                      -service name=foo pattern=/usr/bin/foo state=started
                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      -
                                                                                                                                                                                                                                                      -
                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      setup

                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      This module is automatically called by playbooks to gather useful variables about remote hosts that can be used in playbooks. It can also be executed directly by /usr/bin/ansible to check what variables are available to a host. Ansible provides many facts about the system, automatically.

                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      Obtain facts from all hosts and store them indexed by hostname at /tmp/facts.

                                                                                                                                                                                                                                                      -ansible all -m setup --tree /tmp/facts
                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      Notes

                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      More ansible facts will be added with successive releases. If facter or ohai are installed, variables from these programs will also be snapshotted into the JSON file for usage in templating. These variables are prefixed with facter_ and ohai_ so it's easy to tell their source. All variables are bubbled up to the caller. Using the ansible facts and choosing to not install facter and ohai means you can avoid Ruby-dependencies on your remote systems.

                                                                                                                                                                                                                                                      -
                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      shell

                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      -New in version 0.2.

                                                                                                                                                                                                                                                      -

                                                                                                                                                                                                                                                      The shell module takes the command name followed by a list of arguments, space delimited. It is almost exactly like the command module but runs the command through a shell (/bin/sh) on the remote node.

                                                                                                                                                                                                                                                      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                      parameterrequireddefaultchoicescomments
                                                                                                                                                                                                                                                      createsno
                                                                                                                                                                                                                                                        a filename, when it already exists, this step will NOT be run
                                                                                                                                                                                                                                                        chdirno
                                                                                                                                                                                                                                                          cd into this directory before running the command (0.6 and later)
                                                                                                                                                                                                                                                          (free form)no
                                                                                                                                                                                                                                                            The command module takes a free form command to run

                                                                                                                                                                                                                                                            Execute the command in remote shell

                                                                                                                                                                                                                                                            -shell somescript.sh >> somelog.txt
                                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                                            Notes

                                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                                            If you want to execute a command securely and predicably, it may be better to use the command module instead. Best practices when writing playbooks will follow the trend of using command unless shell is explicitly required. When running ad-hoc commands, use your best judgement.

                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                                            slurp

                                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                                            This module works like fetch. It is used for fetching a base64- encoded blob containing the data in a remote file.

                                                                                                                                                                                                                                                            - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                            parameterrequireddefaultchoicescomments
                                                                                                                                                                                                                                                            srcyes
                                                                                                                                                                                                                                                              The file on the remote system to fetch. This must be a file, not a directory.

                                                                                                                                                                                                                                                              Example using /usr/bin/ansible

                                                                                                                                                                                                                                                              -ansible host -m slurp -a 'src=/tmp/xx'
                                                                                                                                                                                                                                                              -host | success >> {
                                                                                                                                                                                                                                                              -   "content": "aGVsbG8gQW5zaWJsZSB3b3JsZAo=",
                                                                                                                                                                                                                                                              -   "encoding": "base64"
                                                                                                                                                                                                                                                              -}
                                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                                              -

                                                                                                                                                                                                                                                              -

                                                                                                                                                                                                                                                              Notes

                                                                                                                                                                                                                                                              -

                                                                                                                                                                                                                                                              See also: fetch

                                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                                              -

                                                                                                                                                                                                                                                              subversion

                                                                                                                                                                                                                                                              -

                                                                                                                                                                                                                                                              -New in version 0.7.

                                                                                                                                                                                                                                                              -

                                                                                                                                                                                                                                                              This module is really simple, so for now this checks out from the given branch of a repo at a particular SHA or tag. Latest is not supported, you should not be doing that.

                                                                                                                                                                                                                                                              - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                              parameterrequireddefaultchoicescomments
                                                                                                                                                                                                                                                              repoyes
                                                                                                                                                                                                                                                                The subversion URL to the repository.
                                                                                                                                                                                                                                                                destyes
                                                                                                                                                                                                                                                                  Absolute path where the repository should be deployed.
                                                                                                                                                                                                                                                                  forcenoTrue
                                                                                                                                                                                                                                                                  • yes
                                                                                                                                                                                                                                                                  • no
                                                                                                                                                                                                                                                                  If yes, any modified files in the working repository will be discarded. If no, this module will fail if it encounters modified files.

                                                                                                                                                                                                                                                                  Export subversion repository in a specified folder

                                                                                                                                                                                                                                                                  -subversion repo=svn+ssh://an.example.org/path/to/repo dest=/src/checkout
                                                                                                                                                                                                                                                                  -

                                                                                                                                                                                                                                                                  -

                                                                                                                                                                                                                                                                  Notes

                                                                                                                                                                                                                                                                  -

                                                                                                                                                                                                                                                                  Requires subversion and grep on the client.

                                                                                                                                                                                                                                                                  -
                                                                                                                                                                                                                                                                  -

                                                                                                                                                                                                                                                                  supervisorctl

                                                                                                                                                                                                                                                                  -

                                                                                                                                                                                                                                                                  -New in version 0.7.

                                                                                                                                                                                                                                                                  -

                                                                                                                                                                                                                                                                  Manage the state of a program or group of programs running via Supervisord

                                                                                                                                                                                                                                                                  - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                                  parameterrequireddefaultchoicescomments
                                                                                                                                                                                                                                                                  stateyes
                                                                                                                                                                                                                                                                  • started
                                                                                                                                                                                                                                                                  • stopped
                                                                                                                                                                                                                                                                  • restarted
                                                                                                                                                                                                                                                                  The state of service
                                                                                                                                                                                                                                                                  nameyes
                                                                                                                                                                                                                                                                    The name of the supervisord program/process to manage

                                                                                                                                                                                                                                                                    Manage the state of program my_app to be in started state.

                                                                                                                                                                                                                                                                    -supervisorctl name=my_app state=started
                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                    template

                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                    Templates are processed by the Jinja2 templating language (http://jinja.pocoo.org/docs/) - documentation on the template formatting can be found in the Template Designer Documentation (http://jinja.pocoo.org/docs/templates/).

                                                                                                                                                                                                                                                                    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                                    parameterrequireddefaultchoicescomments
                                                                                                                                                                                                                                                                    destyes
                                                                                                                                                                                                                                                                      Location to render the template to on the remote machine.
                                                                                                                                                                                                                                                                      srcyes
                                                                                                                                                                                                                                                                        Path of a Jinja2 formatted template on the local server. This can be a relative or absolute path.
                                                                                                                                                                                                                                                                        backupnono
                                                                                                                                                                                                                                                                        • yes
                                                                                                                                                                                                                                                                        • no
                                                                                                                                                                                                                                                                        Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.
                                                                                                                                                                                                                                                                        othersno
                                                                                                                                                                                                                                                                          all arguments accepted by the file module also work here

                                                                                                                                                                                                                                                                          Example from Ansible Playbooks

                                                                                                                                                                                                                                                                          -template src=/mytemplates/foo.j2 dest=/etc/file.conf owner=bin group=wheel mode=0644
                                                                                                                                                                                                                                                                          -

                                                                                                                                                                                                                                                                          -

                                                                                                                                                                                                                                                                          Notes

                                                                                                                                                                                                                                                                          -

                                                                                                                                                                                                                                                                          Since Ansible version 0.9, templates are loaded with trim_blocks=True.

                                                                                                                                                                                                                                                                          -
                                                                                                                                                                                                                                                                          -

                                                                                                                                                                                                                                                                          user

                                                                                                                                                                                                                                                                          -

                                                                                                                                                                                                                                                                          -New in version 0.2.

                                                                                                                                                                                                                                                                          -

                                                                                                                                                                                                                                                                          Manage user accounts and user attributes.

                                                                                                                                                                                                                                                                          - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                                          parameterrequireddefaultchoicescomments
                                                                                                                                                                                                                                                                          commentno
                                                                                                                                                                                                                                                                            Optionally sets the description (aka GECOS) of user account.
                                                                                                                                                                                                                                                                            shellno
                                                                                                                                                                                                                                                                              Optionally set the user's shell.
                                                                                                                                                                                                                                                                              forcenono
                                                                                                                                                                                                                                                                              • True
                                                                                                                                                                                                                                                                              • False
                                                                                                                                                                                                                                                                              When used with state=absent, behavior is as with userdel --force.
                                                                                                                                                                                                                                                                              nameyes
                                                                                                                                                                                                                                                                                Name of the user to create, remove or modify.
                                                                                                                                                                                                                                                                                createhomenoyes
                                                                                                                                                                                                                                                                                • True
                                                                                                                                                                                                                                                                                • False
                                                                                                                                                                                                                                                                                Unless set to no, a home directory will be made for the user when the account is created.
                                                                                                                                                                                                                                                                                systemnono
                                                                                                                                                                                                                                                                                • True
                                                                                                                                                                                                                                                                                • False
                                                                                                                                                                                                                                                                                When creating an account, setting this to yes makes the user a system account. This setting cannot be changed on existing users.
                                                                                                                                                                                                                                                                                removenono
                                                                                                                                                                                                                                                                                • True
                                                                                                                                                                                                                                                                                • False
                                                                                                                                                                                                                                                                                When used with state=absent, behavior is as with userdel --remove.
                                                                                                                                                                                                                                                                                statenopresent
                                                                                                                                                                                                                                                                                • present
                                                                                                                                                                                                                                                                                • absent
                                                                                                                                                                                                                                                                                Whether the account should exist. When absent, removes the user account.
                                                                                                                                                                                                                                                                                groupsno
                                                                                                                                                                                                                                                                                  Puts the user in this comma-delimited list of groups.
                                                                                                                                                                                                                                                                                  homeno
                                                                                                                                                                                                                                                                                    Optionally set the user's home directory.
                                                                                                                                                                                                                                                                                    groupno
                                                                                                                                                                                                                                                                                      Optionally sets the user's primary group (takes a group name).
                                                                                                                                                                                                                                                                                      passwordno
                                                                                                                                                                                                                                                                                        Optionally set the user's password to this crypted value. See the user example in the github examples directory for what this looks like in a playbook.
                                                                                                                                                                                                                                                                                        appendno
                                                                                                                                                                                                                                                                                          If yes, will only add groups, not set them to just the list in groups.
                                                                                                                                                                                                                                                                                          uidno
                                                                                                                                                                                                                                                                                            Optionally sets the UID of the user.

                                                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                                                                            virt

                                                                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                                                                            -New in version 0.2.

                                                                                                                                                                                                                                                                                            -

                                                                                                                                                                                                                                                                                            Manages virtual machines supported by libvirt.

                                                                                                                                                                                                                                                                                            - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                                                            parameterrequireddefaultchoicescomments
                                                                                                                                                                                                                                                                                            statenono
                                                                                                                                                                                                                                                                                            • running
                                                                                                                                                                                                                                                                                            • shutdown
                                                                                                                                                                                                                                                                                            • destroyed
                                                                                                                                                                                                                                                                                            • undefined
                                                                                                                                                                                                                                                                                            Note that there may be some lag for state requests like shutdown since these refer only to VM states. After starting a guest, it may not be immediately accessible.
                                                                                                                                                                                                                                                                                            commandno
                                                                                                                                                                                                                                                                                              in addition to state management, various non-idempotent commands are available. See examples
                                                                                                                                                                                                                                                                                              nameyes
                                                                                                                                                                                                                                                                                                name of the guest VM being managed

                                                                                                                                                                                                                                                                                                Example from Ansible Playbooks

                                                                                                                                                                                                                                                                                                -virt guest=alpha state=running
                                                                                                                                                                                                                                                                                                -

                                                                                                                                                                                                                                                                                                -

                                                                                                                                                                                                                                                                                                Example guest management with /usr/bin/ansible

                                                                                                                                                                                                                                                                                                -ansible host -m virt -a "guest=alpha command=status"
                                                                                                                                                                                                                                                                                                -

                                                                                                                                                                                                                                                                                                -

                                                                                                                                                                                                                                                                                                Notes

                                                                                                                                                                                                                                                                                                -

                                                                                                                                                                                                                                                                                                Other non-idempotent commands are: status, pause, unpause, get_xml, autostart, freemem, list_vms, info, nodeinfo, virttype

                                                                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                                                                -

                                                                                                                                                                                                                                                                                                vsphere_facts

                                                                                                                                                                                                                                                                                                -

                                                                                                                                                                                                                                                                                                -New in version 0.8.

                                                                                                                                                                                                                                                                                                -

                                                                                                                                                                                                                                                                                                This module gathers facts for a specific guest on VMWare vSphere. These facts include hardware and network related information useful for provisioning (e.g. macaddress, uuid). -This module requires the pysphere python module.

                                                                                                                                                                                                                                                                                                - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                                                                parameterrequireddefaultchoicescomments
                                                                                                                                                                                                                                                                                                hostyes
                                                                                                                                                                                                                                                                                                  The vSphere server from the cluster the virtual server is located on.
                                                                                                                                                                                                                                                                                                  passwordyes
                                                                                                                                                                                                                                                                                                    The password to authenticate on the vSphere cluster.
                                                                                                                                                                                                                                                                                                    loginyes
                                                                                                                                                                                                                                                                                                      The login name to authenticate on the vSphere cluster.
                                                                                                                                                                                                                                                                                                      guestyes
                                                                                                                                                                                                                                                                                                        The virtual server to gather facts for on the vSphere cluster.

                                                                                                                                                                                                                                                                                                        Task to gather facts from a vSphere cluster only if the system is a VMWare guest

                                                                                                                                                                                                                                                                                                        -local_action: vsphere_facts host=$esxserver login=$esxlogin password=$esxpassword guest=$inventory_hostname_short

                                                                                                                                                                                                                                                                                                        only_if: “’$cmdb_hwmodel’.startswith(‘VMWare ‘)

                                                                                                                                                                                                                                                                                                        -
                                                                                                                                                                                                                                                                                                        -
                                                                                                                                                                                                                                                                                                        </pre></p> -<p>Typical output of a vsphere_facts run on a guest</p> <p><pre> -[{‘hw_name’: ‘centos6’, ‘hw_processor_count’: 1, ‘hw_guest_id’: ‘rhel6_64Guest’, ‘hw_memtotal_mb’: 2048, ‘hw_eth0’: [{‘macaddress’: ‘00:11:22:33:44:55’, ‘label’: ‘Network adapter 1’, ‘addresstype’: ‘assigned’, ‘summary’: ‘VLAN-321’, ‘macaddress_dash’: ‘00-11-22-33-44-55’}], ‘hw_product_uuid’: ‘ef50bac8-2845-40ff-81d9-675315501dac’, ‘hw_guest_full_name’: ‘Red Hat Enterprise Linux 6 (64-bit)’}] -</pre></p> -<br/>
                                                                                                                                                                                                                                                                                                        -

                                                                                                                                                                                                                                                                                                        Notes

                                                                                                                                                                                                                                                                                                        -

                                                                                                                                                                                                                                                                                                        This module ought to be run from a system that can access vSphere directly. Either by using local_action, or using delegate_to.

                                                                                                                                                                                                                                                                                                        -
                                                                                                                                                                                                                                                                                                        -

                                                                                                                                                                                                                                                                                                        wait_for

                                                                                                                                                                                                                                                                                                        -

                                                                                                                                                                                                                                                                                                        -New in version 0.7.

                                                                                                                                                                                                                                                                                                        -

                                                                                                                                                                                                                                                                                                        This is useful for when services are not immediately available after their init scripts return - which is true of certain Java application servers. It is also useful when starting guests with the virt module and needing to pause until they are ready.

                                                                                                                                                                                                                                                                                                        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                                                                        parameterrequireddefaultchoicescomments
                                                                                                                                                                                                                                                                                                        delayno
                                                                                                                                                                                                                                                                                                          number of seconds to wait before starting to poll
                                                                                                                                                                                                                                                                                                          hostno127.0.0.1
                                                                                                                                                                                                                                                                                                            hostname or IP address to wait for
                                                                                                                                                                                                                                                                                                            portyes
                                                                                                                                                                                                                                                                                                              port number to poll
                                                                                                                                                                                                                                                                                                              timeoutno300
                                                                                                                                                                                                                                                                                                                maximum number of seconds to wait for
                                                                                                                                                                                                                                                                                                                statenostarted
                                                                                                                                                                                                                                                                                                                • started
                                                                                                                                                                                                                                                                                                                • stopped
                                                                                                                                                                                                                                                                                                                either started, or stopped depending on whether the module should poll for the port being open or closed.

                                                                                                                                                                                                                                                                                                                Example from Ansible Playbooks

                                                                                                                                                                                                                                                                                                                -wait_for port=8000 delay=10
                                                                                                                                                                                                                                                                                                                -

                                                                                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                                                                                -

                                                                                                                                                                                                                                                                                                                yum

                                                                                                                                                                                                                                                                                                                -

                                                                                                                                                                                                                                                                                                                Will install, upgrade, remove, and list packages with the yum package manager.

                                                                                                                                                                                                                                                                                                                - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                                                                                parameterrequireddefaultchoicescomments
                                                                                                                                                                                                                                                                                                                statenopresent
                                                                                                                                                                                                                                                                                                                • present
                                                                                                                                                                                                                                                                                                                • latest
                                                                                                                                                                                                                                                                                                                • absent
                                                                                                                                                                                                                                                                                                                whether to install (present, latest), or remove (absent) a package.
                                                                                                                                                                                                                                                                                                                listno
                                                                                                                                                                                                                                                                                                                  various non-idempotent commands for usage with /usr/bin/ansible and not playbooks. See examples.
                                                                                                                                                                                                                                                                                                                  nameyes
                                                                                                                                                                                                                                                                                                                    package name, or package specifier with version, like name-1.0.

                                                                                                                                                                                                                                                                                                                    -yum name=httpd state=latest
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    -yum name=httpd state=removed
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    -yum name=httpd state=installed
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Additional Contrib Modules

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    In addition to the following built-in modules, community modules are available at Ansible Resources.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Writing your own modules

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    See Module Development.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    See also

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Ansible Resources (Contrib)
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    User contributed playbooks, modules, and articles
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Command Line Examples And Next Steps
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Examples of using modules in /usr/bin/ansible
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Playbooks
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Examples of using modules with /usr/bin/ansible-playbook
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Module Development
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    How to write your own modules
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    API & Integrations
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Examples of using modules with the Python API
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Mailing List
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Questions? Help? Ideas? Stop by the list on Google Groups
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    irc.freenode.net
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    #ansible IRC chat channel
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - - -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - - - \ No newline at end of file diff --git a/docsite/patterns.html b/docsite/patterns.html deleted file mode 100644 index c158b81015d..00000000000 --- a/docsite/patterns.html +++ /dev/null @@ -1,377 +0,0 @@ - - - - - - - - - Inventory & Patterns — Ansible Documentation - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                                                                                    - -
                                                                                                                                                                                                                                                                                                                    - - -
                                                                                                                                                                                                                                                                                                                    - -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Inventory & Patterns

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Ansible works against multiple systems in your infrastructure at the -same time. It does this by selecting portions of systems listed in -Ansible’s inventory file, which defaults to /etc/ansible/hosts.

                                                                                                                                                                                                                                                                                                                    - -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Hosts and Groups

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The format for /etc/ansible/hosts is an INI format and looks like this:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    mail.example.com
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -[webservers]
                                                                                                                                                                                                                                                                                                                    -foo.example.com
                                                                                                                                                                                                                                                                                                                    -bar.example.com
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -[dbservers]
                                                                                                                                                                                                                                                                                                                    -one.example.com
                                                                                                                                                                                                                                                                                                                    -two.example.com
                                                                                                                                                                                                                                                                                                                    -three.example.com
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The things in brackets are group names. You don’t have to have them, -but they are useful.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    If you have hosts that run on non-standard SSH ports you can put the port number -after the hostname with a colon.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    four.example.com:5309
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    In 0.6 and later, if you have a lot of hosts following similar patterns you can do this rather than listing each hostname:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    [webservers]
                                                                                                                                                                                                                                                                                                                    -www[01:50].example.com
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Leading zeros can be included or removed, as desired, and the ranges are inclusive.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Selecting Targets

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    We’ll go over how to use the command line in Command Line Examples And Next Steps section, however, basically it looks like this:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ansible <pattern_goes_here> -m <module_name> -a <arguments>
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Such as:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ansible webservers -m service -a "name=httpd state=restarted"
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Within Playbooks, these patterns can be used for even greater purposes.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Anyway, to use Ansible, you’ll first need to know how to tell Ansible which hosts in your inventory file to talk to. -This is done by designating particular host names or groups of hosts.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The following patterns target all hosts in the inventory file:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    all
                                                                                                                                                                                                                                                                                                                    -*
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Basically ‘all’ is an alias for ‘*’. It is also possible to address a specific host or hosts:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    one.example.com
                                                                                                                                                                                                                                                                                                                    -one.example.com:two.example.com
                                                                                                                                                                                                                                                                                                                    -192.168.1.50
                                                                                                                                                                                                                                                                                                                    -192.168.1.*
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The following patterns address one or more groups, which are denoted -with the aforementioned bracket headers in the inventory file:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    webservers
                                                                                                                                                                                                                                                                                                                    -webservers:dbservers
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    You can exclude groups as well, for instance, all webservers not in Phoenix:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    webservers:!phoenix
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Individual host names (or IPs), but not groups, can also be referenced using -wildcards:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    *.example.com
                                                                                                                                                                                                                                                                                                                    -*.com
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    It’s also ok to mix wildcard patterns and groups at the same time:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    one*.com:dbservers
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Easy enough. See Command Line Examples And Next Steps and then Playbooks for how to do things to selected hosts.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Host Variables

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    It is easy to assign variables to hosts that will be used later in playbooks:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    [atlanta]
                                                                                                                                                                                                                                                                                                                    -host1 http_port=80 maxRequestsPerChild=808
                                                                                                                                                                                                                                                                                                                    -host2 http_port=303 maxRequestsPerChild=909
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Group Variables

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Variables can also be applied to an entire group at once:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    [atlanta]
                                                                                                                                                                                                                                                                                                                    -host1
                                                                                                                                                                                                                                                                                                                    -host2
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -[atlanta:vars]
                                                                                                                                                                                                                                                                                                                    -ntp_server=ntp.atlanta.example.com
                                                                                                                                                                                                                                                                                                                    -proxy=proxy.atlanta.example.com
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Groups of Groups, and Group Variables

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    It is also possible to make groups of groups and assign -variables to groups. These variables can be used by /usr/bin/ansible-playbook, but not -/usr/bin/ansible:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    [atlanta]
                                                                                                                                                                                                                                                                                                                    -host1
                                                                                                                                                                                                                                                                                                                    -host2
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -[raleigh]
                                                                                                                                                                                                                                                                                                                    -host2
                                                                                                                                                                                                                                                                                                                    -host3
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -[southeast:children]
                                                                                                                                                                                                                                                                                                                    -atlanta
                                                                                                                                                                                                                                                                                                                    -raleigh
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -[southeast:vars]
                                                                                                                                                                                                                                                                                                                    -some_server=foo.southeast.example.com
                                                                                                                                                                                                                                                                                                                    -halon_system_timeout=30
                                                                                                                                                                                                                                                                                                                    -self_destruct_countdown=60
                                                                                                                                                                                                                                                                                                                    -escape_pods=2
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -[usa:children]
                                                                                                                                                                                                                                                                                                                    -southeast
                                                                                                                                                                                                                                                                                                                    -northeast
                                                                                                                                                                                                                                                                                                                    -southwest
                                                                                                                                                                                                                                                                                                                    -southeast
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    If you need to store lists or hash data, or prefer to keep host and group specific variables -seperate from the inventory file, see the next section.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Splitting Out Host and Group Specific Data

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    -New in version 0.6.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    In addition to the storing variables directly in the INI file, host -and group variables can be stored in individual files relative to the -inventory file. These variable files are in YAML format.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Assuming the inventory file path is:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    /etc/ansible/hosts
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    If the host is named ‘foosball’, and in groups ‘raleigh’ and ‘webservers’, variables -in YAML files at the following locations will be made available to the host:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    /etc/ansible/group_vars/raleigh
                                                                                                                                                                                                                                                                                                                    -/etc/ansible/group_vars/webservers
                                                                                                                                                                                                                                                                                                                    -/etc/ansible/host_vars/foosball
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    For instance, suppose you have hosts grouped by datacenter, and each datacenter -uses some different servers. The data in the groupfile ‘/etc/ansible/group_vars/raleigh’ for -the ‘raleigh’ group might look like:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -ntp_server: acme.example.org
                                                                                                                                                                                                                                                                                                                    -database_server: storage.example.org
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    It is ok if these files do not exist, this is an optional feature.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Tip: Keeping your inventory file and variables in a git repo (or other version control) -is an excellent way to track changes to your inventory and host variables.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    -New in version 0.5: If you ever have two python interpreters on a system, set a -variable called ‘ansible_python_interpreter’ to the Python -interpreter path you would like to use.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    YAML Inventory

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    -Deprecated since version 0.7.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Ansible’s YAML inventory format is deprecated and will be removed in -Ansible 0.7. Ansible 0.6 includes a conversion script.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Usage:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    yaml_to_ini.py /etc/ansible/hosts
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    See also

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Command Line Examples And Next Steps
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Examples of basic commands
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Playbooks
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Learning ansible’s configuration management language
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Mailing List
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Questions? Help? Ideas? Stop by the list on Google Groups
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    irc.freenode.net
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    #ansible IRC chat channel
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - - -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - - - \ No newline at end of file diff --git a/docsite/playbooks.html b/docsite/playbooks.html deleted file mode 100644 index 82cfb417ce9..00000000000 --- a/docsite/playbooks.html +++ /dev/null @@ -1,550 +0,0 @@ - - - - - - - - - Playbooks — Ansible Documentation - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                                                                                    - -
                                                                                                                                                                                                                                                                                                                    - - -
                                                                                                                                                                                                                                                                                                                    - -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Playbooks

                                                                                                                                                                                                                                                                                                                    - -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Introduction

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Playbooks are a completely different way to use ansible than in task execution mode, and are -particularly powerful. Simply put, playbooks are the basis for a really simple -configuration management and multi-machine deployment system, -unlike any that already exist, and one that is very well suited to deploying complex applications.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Playbooks can declare configurations, but they can also orchestrate steps of -any manual ordered process, even as different steps must bounce back and forth -between sets of machines in particular orders. They can launch tasks -synchronously or asynchronously.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    While you might run the main /usr/bin/ansible program for ad-hoc -tasks, playbooks are more likely to be kept in source control and used -to push out your configuration or assure the configurations of your -remote systems are in spec.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Let’s dive in and see how they work. As you go, you may wish to open -the github examples directory in -another tab, so you can apply the theory to what things look like in practice.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Playbook Language Example

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Playbooks are expressed in YAML format and have a minimum of syntax. -Each playbook is composed of one or more ‘plays’ in a list.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The goal of a play is map a group of hosts to some well defined roles, represented by -things ansible called tasks. At the basic level, a task is nothing more than a call -to an ansible module, which you should have learned about in earlier chapters.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    By composing a playbook of multiple ‘plays’, it is possible to -orchestrate multi-machine deployments, running certain steps on all -machines in the webservers group, then certain steps on the database -server group, then more commands back on the webservers group, etc.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    For starters, here’s a playbook that contains just one play:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -- hosts: webservers
                                                                                                                                                                                                                                                                                                                    -  vars:
                                                                                                                                                                                                                                                                                                                    -    http_port: 80
                                                                                                                                                                                                                                                                                                                    -    max_clients: 200
                                                                                                                                                                                                                                                                                                                    -  user: root
                                                                                                                                                                                                                                                                                                                    -  tasks:
                                                                                                                                                                                                                                                                                                                    -  - name: ensure apache is at the latest version
                                                                                                                                                                                                                                                                                                                    -    action: yum pkg=httpd state=latest
                                                                                                                                                                                                                                                                                                                    -  - name: write the apache config file
                                                                                                                                                                                                                                                                                                                    -    action: template src=/srv/httpd.j2 dest=/etc/httpd.conf
                                                                                                                                                                                                                                                                                                                    -    notify:
                                                                                                                                                                                                                                                                                                                    -    - restart apache
                                                                                                                                                                                                                                                                                                                    -  - name: ensure apache is running
                                                                                                                                                                                                                                                                                                                    -    action: service name=httpd state=started
                                                                                                                                                                                                                                                                                                                    -  handlers:
                                                                                                                                                                                                                                                                                                                    -    - name: restart apache
                                                                                                                                                                                                                                                                                                                    -      action: service name=httpd state=restarted
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Below, we’ll break down what the various features of the playbook language are.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Basics

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Hosts and Users

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    For each play in a playbook, you get to choose which machines in your infrastructure -to target and what remote user to complete the steps (called tasks) as.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The hosts line is a list of one or more groups or host patterns, -separated by colons, as described in the Inventory & Patterns -documentation. The user is just the name of the user account:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -- hosts: webservers
                                                                                                                                                                                                                                                                                                                    -  user: root
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Support for running things from sudo is also available:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -- hosts: webservers
                                                                                                                                                                                                                                                                                                                    -  user: yourname
                                                                                                                                                                                                                                                                                                                    -  sudo: True
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    You can also login as you, and then sudo to different users than root:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -- hosts: webservers
                                                                                                                                                                                                                                                                                                                    -  user: yourname
                                                                                                                                                                                                                                                                                                                    -  sudo: True
                                                                                                                                                                                                                                                                                                                    -  sudo_user: postgres
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    If you need to specify a password to sudo, run ansible-playbook with --ask-sudo-pass (-K). -If you run a sudo playbook and the playbook seems to hang, it’s probably stuck at the sudo prompt. -Just Control-C to kill it and run it again with -K.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Important

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    When using sudo_user to a user other than root, the module -arguments are briefly written into a random tempfile in /tmp. -These are deleted immediately after the command is executed. This -only occurs when sudoing from a user like ‘bob’ to ‘timmy’, not -when going from ‘bob’ to ‘root’, or logging in directly as ‘bob’ or -‘root’. If this concerns you that this data is briefly readable -(not writeable), avoid transferring uncrypted passwords with -sudo_user set. In other cases, ‘/tmp’ is not used and this does -not come into play. Ansible also takes care to not log password -parameters.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Vars section

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The vars section contains a list of variables and values that can be used in the plays, like this:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -- hosts: webservers
                                                                                                                                                                                                                                                                                                                    -  user: root
                                                                                                                                                                                                                                                                                                                    -  vars:
                                                                                                                                                                                                                                                                                                                    -     http_port: 80
                                                                                                                                                                                                                                                                                                                    -     van_halen_port: 5150
                                                                                                                                                                                                                                                                                                                    -     other: 'magic'
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    These variables can be used later in the playbook like this:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    $varname or ${varname}
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The later is useful in the event you need to do something like ${other}_some_string.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Inside templates, the full power of the Jinja2 templating language is also available, which looks like this:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    {{ varname }}
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The Jinja2 documentation provides information about how to construct loops and conditionals for those -who which to use more advanced templating. This is optional and the $varname format still works in template -files.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    If there are discovered variables about the system, called ‘facts’, these variables bubble up back into the -playbook, and can be used on each system just like explicitly set variables. Ansible provides several -of these, prefixed with ‘ansible’, and are documented under ‘setup’ in the module documentation. Additionally, -facts can be gathered by ohai and facter if they are installed. Facter variables are prefixed with facter_ and Ohai -variables are prefixed with ohai_.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    So for instance, if I wanted -to write the hostname into the /etc/motd file, I could say:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - name: write the motd
                                                                                                                                                                                                                                                                                                                    -  action: template src=/srv/templates/motd.j2 dest=/etc/motd
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    And in /srv/templates/motd.j2:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    You are logged into {{ facter_hostname }}
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    But we’re getting ahead of ourselves. Let’s talk about tasks.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Tasks list

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Each play contains a list of tasks. Tasks are executed in order, one -at a time, against all machines matched by the host pattern, -before moving on to the next task. It is important to understand that, within a play, -all hosts are going to get the same task directives. It is the purpose of a play to map -a selection of hosts to tasks.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    When running the playbook, which runs top to bottom, hosts with failed tasks are -taken out of the rotation for the entire playbook. If things fail, simply correct the playbook file and rerun.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The goal of each task is to execute a module, with very specific arguments. -Variables, as mentioned above, can be used in arguments to modules.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Modules are ‘idempotent’, meaning if you run them -again, they will make the changes they are told to make to bring the -system to the desired state. This makes it very safe to rerun -the same playbook multiple times. They won’t change things -unless they have to change things.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The command and shell modules will typically rerun the same command again, -which is totally ok if the command is something like -‘chmod’ or ‘setsebool’, etc. Though there is a ‘creates’ flag available which can -be used to make these modules also idempotent.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Every task should have a name, which is included in the output from -running the playbook. This is output for humans, so it is -nice to have reasonably good descriptions of each task step. If the name -is not provided though, the string fed to ‘action’ will be used for -output.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Here is what a basic task looks like, as with most modules, -the service module takes key=value arguments:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    tasks:
                                                                                                                                                                                                                                                                                                                    -  - name: make sure apache is running
                                                                                                                                                                                                                                                                                                                    -    action: service name=httpd state=running
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The command and shell modules are the one modules that just takes a list -of arguments, and don’t use the key=value form. This makes -them work just like you would expect. Simple:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    tasks:
                                                                                                                                                                                                                                                                                                                    -  - name: disable selinux
                                                                                                                                                                                                                                                                                                                    -    action: command /sbin/setenforce 0
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The command and shell module care about return codes, so if you have a command -who’s successful exit code is not zero, you may wish to do this:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    tasks:
                                                                                                                                                                                                                                                                                                                    -  - name: run this command and ignore the result
                                                                                                                                                                                                                                                                                                                    -    action: shell /usr/bin/somecommand & /bin/true
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Variables can be used in action lines. Suppose you defined -a variable called ‘vhost’ in the ‘vars’ section, you could do this:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    tasks:
                                                                                                                                                                                                                                                                                                                    -  - name: create a virtual host file for $vhost
                                                                                                                                                                                                                                                                                                                    -    action: template src=somefile.j2 dest=/etc/httpd/conf.d/$vhost
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Those same variables are usable in templates, which we’ll get to later.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Now in a very basic playbook all the tasks will be listed directly in that play, though it will usually -make more sense to break up tasks using the ‘include:’ directive. We’ll show that a bit later.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Running Operations On Change

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    As we’ve mentioned, modules are written to be ‘idempotent’ and can relay when -they have made a change on the remote system. Playbooks recognize this and -have a basic event system that can be used to respond to change.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    These ‘notify’ actions are triggered at the end of each ‘play’ in a playbook, and -trigger only once each. For instance, multiple resources may indicate -that apache needs to be restarted, but apache will only be bounced once.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Here’s an example of restarting two services when the contents of a file -change, but only if the file changes:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - name: template configuration file
                                                                                                                                                                                                                                                                                                                    -  action: template src=template.j2 dest=/etc/foo.conf
                                                                                                                                                                                                                                                                                                                    -  notify:
                                                                                                                                                                                                                                                                                                                    -     - restart memcached
                                                                                                                                                                                                                                                                                                                    -     - restart apache
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The things listed in the ‘notify’ section of a task are called -handlers.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Handlers are lists of tasks, not really any different from regular -tasks, that are referenced by name. Handlers are what notifiers -notify. If nothing notifies a handler, it will not run. Regardless -of how many things notify a handler, it will run only once, after all -of the tasks complete in a particular play.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Here’s an example handlers section:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    handlers:
                                                                                                                                                                                                                                                                                                                    -    - name: restart memcached
                                                                                                                                                                                                                                                                                                                    -      action: service name=memcached state=restarted
                                                                                                                                                                                                                                                                                                                    -    - name: restart apache
                                                                                                                                                                                                                                                                                                                    -      action: service name=apache state=restarted
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Handlers are best used to restart services and trigger reboots. You probably -won’t need them for much else.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Note

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Notify handlers are always run in the order written.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Include Files And Encouraging Reuse

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Suppose you want to reuse lists of tasks between plays or playbooks. You can use -include files to do this. Use of included task lists is a great way to define a role -that system is going to fulfill. Remember, the goal of a play in a playbook is to map -a group of systems into multiple roles. Let’s see what this looks like...

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    A task include file simply contains a flat list of tasks, like so:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -# possibly saved as tasks/foo.yml
                                                                                                                                                                                                                                                                                                                    -- name: placeholder foo
                                                                                                                                                                                                                                                                                                                    -  action: command /bin/foo
                                                                                                                                                                                                                                                                                                                    -- name: placeholder bar
                                                                                                                                                                                                                                                                                                                    -  action: command /bin/bar
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Include directives look like this, and can be mixed in with regular tasks in a playbook:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    tasks:
                                                                                                                                                                                                                                                                                                                    - - include: tasks/foo.yml
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    You can also pass variables into includes. We call this a ‘parameterized include’.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    For instance, if deploying multiple wordpress instances, I could -contain all of my wordpress tasks in a single wordpress.yml file, and use it like so:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    tasks:
                                                                                                                                                                                                                                                                                                                    -  - include: wordpress.yml user=timmy
                                                                                                                                                                                                                                                                                                                    -  - include: wordpress.yml user=alice
                                                                                                                                                                                                                                                                                                                    -  - include: wordpress.yml user=bob
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Variables passed in can then be used in the included files. You can reference them like this:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    $user
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    (In addition to the explicitly passed in parameters, all variables from -the vars section are also available for use here as well.)

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Note

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Task include statements are only usable one-level deep. -This means task includes can not include other -task includes. This may change in a later release.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Includes can also be used in the ‘handlers’ section, for instance, if you -want to define how to restart apache, you only have to do that once for all -of your playbooks. You might make a handlers.yml that looks like:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ----
                                                                                                                                                                                                                                                                                                                    -# this might be in a file like handlers/handlers.yml
                                                                                                                                                                                                                                                                                                                    -- name: restart apache
                                                                                                                                                                                                                                                                                                                    -  action: service name=apache state=restarted
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    And in your main playbook file, just include it like so, at the bottom -of a play:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    handlers:
                                                                                                                                                                                                                                                                                                                    -  - include: handlers/handlers.yml
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    You can mix in includes along with your regular non-included tasks and handlers.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Includes can also be used to import one playbook file into another. This allows -you to define a top-level playbook that is composed of other playbooks.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    For example:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - name: this is a play at the top level of a file
                                                                                                                                                                                                                                                                                                                    -  hosts: all
                                                                                                                                                                                                                                                                                                                    -  user: root
                                                                                                                                                                                                                                                                                                                    -  tasks:
                                                                                                                                                                                                                                                                                                                    -  - name: say hi
                                                                                                                                                                                                                                                                                                                    -    tags: foo
                                                                                                                                                                                                                                                                                                                    -    action: shell echo "hi..."
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -- include: load_balancers.yml
                                                                                                                                                                                                                                                                                                                    -- include: webservers.yml
                                                                                                                                                                                                                                                                                                                    -- include: dbservers.yml
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Note that you cannot do variable substitution when including one playbook -inside another.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Note

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    You can not conditionally path the location to an include file, -like you can with ‘vars_files’. If you find yourself needing to do -this, consider how you can restructure your playbook to be more -class/role oriented. This is to say you cannot use a ‘fact’ to -decide what include file to use. All hosts contained within the -play are going to get the same tasks. (‘only_if’ provides some -ability for hosts to conditionally skip tasks).

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Executing A Playbook

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Now that you’ve learned playbook syntax, how do you run a playbook? It’s simple. -Let’s run a playbook using a parallelism level of 10:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ansible-playbook playbook.yml -f 10
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Tips and Tricks

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Look at the bottom of the playbook execution for a summary of the nodes that were executed -and how they performed. General failures and fatal “unreachable” communication attempts are -kept seperate in the counts.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    If you ever want to see detailed output from successful modules as well as unsuccessful ones, -use the ‘–verbose’ flag. This is available in Ansible 0.5 and later.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Also, in version 0.5 and later, Ansible playbook output is vastly upgraded if the cowsay -package is installed. Try it!

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    In version 0.7 and later, to see what hosts would be affected by a playbook before you run it, you -can do this:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ansible-playbook playbook.yml --list-hosts.
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    See also

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    YAML Syntax
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Learn about YAML syntax
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Playbooks
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Review the basic Playbook language features
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Advanced Playbooks
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Learn about Advanced Playbook Features
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Best Practices
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Various tips about managing playbooks in the real world
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Ansible Modules
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Learn about available modules
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Module Development
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Learn how to extend Ansible by writing your own modules
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Inventory & Patterns
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Learn about how to select hosts
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Github examples directory
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Complete playbook files from the github project source
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Mailing List
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Questions? Help? Ideas? Stop by the list on Google Groups
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - - -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - - - \ No newline at end of file diff --git a/docsite/playbooks2.html b/docsite/playbooks2.html deleted file mode 100644 index 3bf696641a1..00000000000 --- a/docsite/playbooks2.html +++ /dev/null @@ -1,723 +0,0 @@ - - - - - - - - - Advanced Playbooks — Ansible Documentation - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                                                                                    - -
                                                                                                                                                                                                                                                                                                                    - - -
                                                                                                                                                                                                                                                                                                                    - -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Advanced Playbooks

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Here are some advanced features of the playbooks language. Using all of these features -are not neccessary, but many of them will prove useful. If a feature doesn’t seem immediately -relevant, feel free to skip it. For many people, the features documented in playbooks will -be 90% or more of what they use in Ansible.

                                                                                                                                                                                                                                                                                                                    - -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Tags

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    -New in version 0.6.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    If you have a large playbook it may become useful to be able to run a -specific part of the configuration. Both plays and tasks support a -“tags:” attribute for this reason.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Example:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    tasks:
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -    - action: yum name=$item state=installed
                                                                                                                                                                                                                                                                                                                    -      with_items:
                                                                                                                                                                                                                                                                                                                    -         - httpd
                                                                                                                                                                                                                                                                                                                    -         - memcached
                                                                                                                                                                                                                                                                                                                    -      tags:
                                                                                                                                                                                                                                                                                                                    -         - packages
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -    - action: template src=templates/src.j2 dest=/etc/foo.conf
                                                                                                                                                                                                                                                                                                                    -      tags:
                                                                                                                                                                                                                                                                                                                    -         - configuration
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    If you wanted to just run the “configuration” and “packages” part of a very long playbook, you could do this:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ansible-playbook example.yml --tags "configuration,packages"
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Playbooks Including Playbooks

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    -New in version 0.6.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    To further advance the concept of include files, playbook files can -include other playbook files. Suppose you define the behavior of all -your webservers in “webservers.yml” and all your database servers in -“dbservers.yml”. You can create a “site.yml” that would reconfigure -all of your systems like this:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ----
                                                                                                                                                                                                                                                                                                                    -- include: playbooks/webservers.yml
                                                                                                                                                                                                                                                                                                                    -- include: playbooks/dbservers.yml
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    This concept works great with tags to rapidly select exactly what plays you want to run, and exactly -what parts of those plays.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Ignoring Failed Commands

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    -Deprecated since version 0.6.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Generally playbooks will stop executing any more steps on a host that -has a failure. Sometimes, though, you want to continue on. To do so, -write a task that looks like this:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - name: this will not be counted as a failure
                                                                                                                                                                                                                                                                                                                    -  action: command /bin/false
                                                                                                                                                                                                                                                                                                                    -  ignore_errors: True
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Accessing Complex Variable Data

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Some provided facts, like networking information, are made available as nested data structures. To access -them a simple ‘$foo’ is not sufficient, but it is still easy to do. Here’s how we get an IP address:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ${ansible_eth0.ipv4.address}
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    It is also possible to access variables whose elements are arrays:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ${somelist[0]}
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    And the array and hash reference syntaxes can be mixed.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    In templates, the simple access form still holds, but they can also be accessed from Jinja2 in more Python-native ways if -that is preferred:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    {{ ansible_eth0["ipv4"]["address"] }}
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Accessing Information About Other Hosts

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    If your database server wants to check the value of a ‘fact’ from another node, or an inventory variable -assigned to another node, it’s easy to do so within a template or even an action line:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ${hostvars.hostname.factname}
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Note

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    No database or other complex system is required to exchange data -between hosts. The hosts that you want to reference data from must -be included in either the current play or any previous play.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Additionally, group_names is a list (array) of all the groups the current host is in. This can be used in templates using Jinja2 syntax to make template source files that vary based on the group membership (or role) of the host:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    {% if 'webserver' in group_names %}
                                                                                                                                                                                                                                                                                                                    -   # some part of a configuration file that only applies to webservers
                                                                                                                                                                                                                                                                                                                    -{% endif %}
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    groups is a list of all the groups (and hosts) in the inventory. This can be used to enumerate all hosts within a group. -For example:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    {% for host in groups['app_servers'] %}
                                                                                                                                                                                                                                                                                                                    -   # something that applies to all app servers.
                                                                                                                                                                                                                                                                                                                    -{% endfor %}
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Use cases include pointing a frontend proxy server to all of the app servers, setting up the correct firewall rules between servers, etc.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    inventory_hostname is the name of the hostname as configured in Ansible’s inventory host file. This can -be useful for when you don’t want to rely on the discovered hostname ansible_hostname or for other mysterious -reasons. If you have a long FQDN, inventory_hostname_short (in Ansible 0.6) also contains the part up to the first -period.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Don’t worry about any of this unless you think you need it. You’ll know when you do.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Variable File Seperation

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    It’s a great idea to keep your playbooks under source control, but -you may wish to make the playbook source public while keeping certain -important variables private. Similarly, sometimes you may just -want to keep certain information in different files, away from -the main playbook.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    You can do this by using an external variables file, or files, just like this:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -- hosts: all
                                                                                                                                                                                                                                                                                                                    -  user: root
                                                                                                                                                                                                                                                                                                                    -  vars:
                                                                                                                                                                                                                                                                                                                    -    favcolor: blue
                                                                                                                                                                                                                                                                                                                    -  vars_files:
                                                                                                                                                                                                                                                                                                                    -    - /vars/external_vars.yml
                                                                                                                                                                                                                                                                                                                    -  tasks:
                                                                                                                                                                                                                                                                                                                    -  - name: this is just a placeholder
                                                                                                                                                                                                                                                                                                                    -    action: command /bin/echo foo
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    This removes the risk of sharing sensitive data with others when -sharing your playbook source with them.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The contents of each variables file is a simple YAML dictionary, like this:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -# in the above example, this would be vars/external_vars.yml
                                                                                                                                                                                                                                                                                                                    -somevar: somevalue
                                                                                                                                                                                                                                                                                                                    -password: magic
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Note

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    It’s also possible to keep per-host and per-group variables in very -similar files, this is covered in Inventory & Patterns.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Prompting For Sensitive Data

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    You may wish to prompt the user for certain input, and can -do so with the similarly named ‘vars_prompt’ section. This has uses -beyond security, for instance, you may use the same playbook for all -software releases and would prompt for a particular release version -in a push-script:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -- hosts: all
                                                                                                                                                                                                                                                                                                                    -  user: root
                                                                                                                                                                                                                                                                                                                    -  vars:
                                                                                                                                                                                                                                                                                                                    -    from: "camelot"
                                                                                                                                                                                                                                                                                                                    -  vars_prompt:
                                                                                                                                                                                                                                                                                                                    -    name: "what is your name?"
                                                                                                                                                                                                                                                                                                                    -    quest: "what is your quest?"
                                                                                                                                                                                                                                                                                                                    -    favcolor: "what is your favorite color?"
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    There are full examples of both of these items in the github examples/playbooks directory.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    An alternative form of vars_prompt allows for hiding input from the user, and may later support -some other options, but otherwise works equivalently:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    vars_prompt:
                                                                                                                                                                                                                                                                                                                    -  - name: "some_password"
                                                                                                                                                                                                                                                                                                                    -    prompt: "Enter password"
                                                                                                                                                                                                                                                                                                                    -    private: True
                                                                                                                                                                                                                                                                                                                    -  - name: "release_version"
                                                                                                                                                                                                                                                                                                                    -    prompt: "Product release version"
                                                                                                                                                                                                                                                                                                                    -    private: False
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Passing Variables On The Command Line

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    In addition to vars_prompt and vars_files, it is possible to send variables over -the ansible command line. This is particularly useful when writing a generic release playbook -where you may want to pass in the version of the application to deploy:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ansible-playbook release.yml --extra-vars "version=1.23.45 other_variable=foo"
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    This is useful, for, among other things, setting the hosts group or the user for the playbook.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Example:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -----
                                                                                                                                                                                                                                                                                                                    -- user: $user
                                                                                                                                                                                                                                                                                                                    -  hosts: $hosts
                                                                                                                                                                                                                                                                                                                    -  tasks:
                                                                                                                                                                                                                                                                                                                    -     - ...
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -ansible-playbook release.yml --extra-vars "hosts=vipers user=starbuck"
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Conditional Execution

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Sometimes you will want to skip a particular step on a particular host. This could be something -as simple as not installing a certain package if the operating system is a particular version, -or it could be something like performing some cleanup steps if a filesystem is getting full.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    This is easy to do in Ansible, with the only_if clause, which actually is a Python expression. -Don’t panic – it’s actually pretty simple:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    vars:
                                                                                                                                                                                                                                                                                                                    -  favcolor: blue
                                                                                                                                                                                                                                                                                                                    -  is_favcolor_blue: "'$favcolor' == 'blue'"
                                                                                                                                                                                                                                                                                                                    -  is_centos: "'$facter_operatingsystem' == 'CentOS'"
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -tasks:
                                                                                                                                                                                                                                                                                                                    -  - name: "shutdown if my favorite color is blue"
                                                                                                                                                                                                                                                                                                                    -    action: command /sbin/shutdown -t now
                                                                                                                                                                                                                                                                                                                    -    only_if: '$is_favcolor_blue'
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Variables from tools like facter and ohai can be used here, if installed, or you can -use variables that bubble up from ansible, which many are provided by the setup module. As a reminder, -these variables are prefixed, so it’s $facter_operatingsystem, not $operatingsystem. Ansible’s -built in variables are prefixed with ansible_.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The only_if expression is actually a tiny small bit of Python, so be sure to quote variables and make something -that evaluates to True or False. It is a good idea to use ‘vars_files’ instead of ‘vars’ to define -all of your conditional expressions in a way that makes them very easy to reuse between plays -and playbooks.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    You cannot use live checks here, like ‘os.path.exists’, so don’t try.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    It’s also easy to provide your own facts if you want, which is covered in Module Development. To run them, just -make a call to your own custom fact gathering module at the top of your list of tasks, and variables returned -there will be accessible to future tasks:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    tasks:
                                                                                                                                                                                                                                                                                                                    -    - name: gather site specific fact data
                                                                                                                                                                                                                                                                                                                    -      action: site_facts
                                                                                                                                                                                                                                                                                                                    -    - action: command echo ${my_custom_fact_can_be_used_now}
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Conditional Imports

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Sometimes you will want to do certain things differently in a playbook based on certain criteria. -Having one playbook that works on multiple platforms and OS versions is a good example.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    As an example, the name of the Apache package may be different between CentOS and Debian, -but it is easily handled with a minimum of syntax in an Ansible Playbook:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -- hosts: all
                                                                                                                                                                                                                                                                                                                    -  user: root
                                                                                                                                                                                                                                                                                                                    -  vars_files:
                                                                                                                                                                                                                                                                                                                    -    - "vars/common.yml"
                                                                                                                                                                                                                                                                                                                    -    - [ "vars/$facter_operatingsystem.yml", "vars/os_defaults.yml" ]
                                                                                                                                                                                                                                                                                                                    -  tasks:
                                                                                                                                                                                                                                                                                                                    -  - name: make sure apache is running
                                                                                                                                                                                                                                                                                                                    -    action: service name=$apache state=running
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Note

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The variable ($facter_operatingsystem) is being interpolated into -the list of filenames being defined for vars_files.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    As a reminder, the various YAML files contain just keys and values:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -# for vars/CentOS.yml
                                                                                                                                                                                                                                                                                                                    -apache: httpd
                                                                                                                                                                                                                                                                                                                    -somethingelse: 42
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    How does this work? If the operating system was ‘CentOS’, the first file Ansible would try to import -would be ‘vars/CentOS.yml’, followed up by ‘/vars/os_defaults.yml’ if that file -did not exist. If no files in the list were found, an error would be raised. -On Debian, it would instead first look towards ‘vars/Debian.yml’ instead of ‘vars/CentOS.yml’, before -falling back on ‘vars/os_defaults.yml’. Pretty simple.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    To use this conditional import feature, you’ll need facter or ohai installed prior to running the playbook, but -you can of course push this out with Ansible if you like:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    # for facter
                                                                                                                                                                                                                                                                                                                    -ansible -m yum -a "pkg=facter ensure=installed"
                                                                                                                                                                                                                                                                                                                    -ansible -m yum -a "pkg=ruby-json ensure=installed"
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -# for ohai
                                                                                                                                                                                                                                                                                                                    -ansible -m yum -a "pkg=ohai ensure=installed"
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Ansible’s approach to configuration – seperating variables from tasks, keeps your playbooks -from turning into arbitrary code with ugly nested ifs, conditionals, and so on - and results -in more streamlined & auditable configuration rules – especially because there are a -minimum of decision points to track.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Loops

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    To save some typing, repeated tasks can be written in short-hand like so:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - name: add user $item
                                                                                                                                                                                                                                                                                                                    -  action: user name=$item state=present groups=wheel
                                                                                                                                                                                                                                                                                                                    -  with_items:
                                                                                                                                                                                                                                                                                                                    -     - testuser1
                                                                                                                                                                                                                                                                                                                    -     - testuser2
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    If you have defined a YAML list in a variables file, or the ‘vars’ section, you can also do:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    with_items: $somelist
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The above would be the equivalent of:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - name: add user testuser1
                                                                                                                                                                                                                                                                                                                    -  action: user name=testuser1 state=present groups=wheel
                                                                                                                                                                                                                                                                                                                    -- name: add user testuser2
                                                                                                                                                                                                                                                                                                                    -  action: user name=testuser2 state=present groups=wheel
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The yum and apt modules use with_items to execute fewer package manager transactions.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Selecting Files And Templates Based On Variables

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Sometimes a configuration file you want to copy, or a template you will use may depend on a variable. -The following construct selects the first available file appropriate for the variables of a given host, -which is often much cleaner than putting a lot of if conditionals in a template.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The following example shows how to template out a configuration file that was very different between, say, -CentOS and Debian:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - name: template a file
                                                                                                                                                                                                                                                                                                                    -  action: template src=$item dest=/etc/myapp/foo.conf
                                                                                                                                                                                                                                                                                                                    -  first_available_file:
                                                                                                                                                                                                                                                                                                                    -    - /srv/templates/myapp/${ansible_distribution}.conf
                                                                                                                                                                                                                                                                                                                    -    - /srv/templates/myapp/default.conf
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Asynchronous Actions and Polling

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    By default tasks in playbooks block, meaning the connections stay open -until the task is done on each node. If executing playbooks with -a small parallelism value (aka --forks), you may wish that long -running operations can go faster. The easiest way to do this is -to kick them off all at once and then poll until they are done.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    You will also want to use asynchronous mode on very long running -operations that might be subject to timeout.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    To launch a task asynchronously, specify its maximum runtime -and how frequently you would like to poll for status. The default -poll value is 10 seconds if you do not specify a value for poll:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -- hosts: all
                                                                                                                                                                                                                                                                                                                    -  user: root
                                                                                                                                                                                                                                                                                                                    -  tasks:
                                                                                                                                                                                                                                                                                                                    -  - name: simulate long running op (15 sec), wait for up to 45, poll every 5
                                                                                                                                                                                                                                                                                                                    -    action: command /bin/sleep 15
                                                                                                                                                                                                                                                                                                                    -    async: 45
                                                                                                                                                                                                                                                                                                                    -    poll: 5
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Note

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    There is no default for the async time limit. If you leave off the -‘async’ keyword, the task runs synchronously, which is Ansible’s -default.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Alternatively, if you do not need to wait on the task to complete, you may -“fire and forget” by specifying a poll value of 0:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -- hosts: all
                                                                                                                                                                                                                                                                                                                    -  user: root
                                                                                                                                                                                                                                                                                                                    -  tasks:
                                                                                                                                                                                                                                                                                                                    -  - name: simulate long running op, allow to run for 45, fire and forget
                                                                                                                                                                                                                                                                                                                    -    action: command /bin/sleep 15
                                                                                                                                                                                                                                                                                                                    -    async: 45
                                                                                                                                                                                                                                                                                                                    -    poll: 0
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Note

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    You shouldn’t “fire and forget” with operations that require -exclusive locks, such as yum transactions, if you expect to run other -commands later in the playbook against those same resources.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Note

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Using a higher value for --forks will result in kicking off asynchronous -tasks even faster. This also increases the efficiency of polling.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Local Playbooks

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    It may be useful to use a playbook locally, rather than by connecting over SSH. This can be useful -for assuring the configuration of a system by putting a playbook on a crontab. This may also be used -to run a playbook inside a OS installer, such as an Anaconda kickstart.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    To run an entire playbook locally, just set the “hosts:” line to “hosts:127.0.0.1” and then run the playbook like so:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ansible-playbook playbook.yml --connection=local
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Alternatively, a local connection can be used in a single playbook play, even if other plays in the playbook -use the default remote connection type:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    hosts: 127.0.0.1
                                                                                                                                                                                                                                                                                                                    -connection: local
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Turning Off Facts

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    If you know you don’t need any fact data about your hosts, and know everything about your systems centrally, you -can turn off fact gathering. This has advantages in scaling ansible in push mode with very large numbers of -systems, mainly, or if you are using Ansible on experimental platforms. In any play, just do this:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - hosts: whatever
                                                                                                                                                                                                                                                                                                                    -  gather_facts: False
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Pull-Mode Playbooks

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The use of playbooks in local mode (above) is made extremely powerful with the addition of ansible-pull. -A script for setting up ansible-pull is provided in the examples/playbooks directory of the source -checkout.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The basic idea is to use Ansible to set up a remote copy of ansible on each managed node, each set to run via -cron and update playbook source via git. This interverts the default push architecture of ansible into a pull -architecture, which has near-limitless scaling potential. The setup playbook can be tuned to change -the cron frequency, logging locations, and parameters to ansible-pull.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    This is useful both for extreme scale-out as well as periodic remediation. Usage of the ‘fetch’ module to retrieve -logs from ansible-pull runs would be an excellent way to gather and analyze remote logs from ansible-pull.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Register Variables

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    -New in version 0.7.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Often in a playbook it may be useful to store the result of a given command in a variable and access -it later. Use of the command module in this way can in many ways eliminate the need to write site specific facts, for -instance, you could test for the existance of a particular program.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    The ‘register’ keyword decides what variable to save a result in. The resulting variables can be used in templates, action lines, or only_if statements. It looks like this (in an obviously trivial example):

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - name: test play
                                                                                                                                                                                                                                                                                                                    -  hosts: all
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -  tasks:
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -      - action: shell cat /etc/motd
                                                                                                                                                                                                                                                                                                                    -        register: motd_contents
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -      - action: shell echo "motd contains the word hi"
                                                                                                                                                                                                                                                                                                                    -        only_if: "'${motd_contents.stdout}'.find('hi') != -1"
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Rolling Updates

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    -New in version 0.7.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    By default ansible will try to manage all of the machines referenced in a play in parallel. For a rolling updates -use case, you can define how many hosts ansible should manage at a single time by using the ‘’serial’’ keyword:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - name: test play
                                                                                                                                                                                                                                                                                                                    -  hosts: webservers
                                                                                                                                                                                                                                                                                                                    -  serial: 3
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    In the above example, if we had 100 hosts, 3 hosts in the group ‘webservers’ -would complete the play completely before moving on to the next 3 hosts.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Delegation

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    -New in version 0.7.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    If you want to perform a task on one host with reference to other hosts, use the ‘delegate_to’ keyword on a task. -This is ideal for placing nodes in a load balanced pool, or removing them. It is also very useful for controlling -outage windows. Using this with the ‘serial’ keyword to control the number of hosts executing at one time is also -a good idea:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -- hosts: webservers
                                                                                                                                                                                                                                                                                                                    -  serial: 5
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -  tasks:
                                                                                                                                                                                                                                                                                                                    -  - name: take out of load balancer pool
                                                                                                                                                                                                                                                                                                                    -    action: command /usr/bin/take_out_of_pool $inventory_hostname
                                                                                                                                                                                                                                                                                                                    -    delegate_to: 127.0.0.1
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -  - name: actual steps would go here
                                                                                                                                                                                                                                                                                                                    -    action: yum name=acme-web-stack state=latest
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -  - name: add back to load balancer pool
                                                                                                                                                                                                                                                                                                                    -    action: command /usr/bin/add_back_to_pool $inventory_hostname
                                                                                                                                                                                                                                                                                                                    -    delegate_to: 127.0.0.1
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Here is the same playbook as above, but using the shorthand syntax, -‘local_action’, for delegating to 127.0.0.1:

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    ---
                                                                                                                                                                                                                                                                                                                    -# ...
                                                                                                                                                                                                                                                                                                                    -  tasks:
                                                                                                                                                                                                                                                                                                                    -  - name: take out of load balancer pool
                                                                                                                                                                                                                                                                                                                    -    local_action: command /usr/bin/take_out_of_pool $inventory_hostname
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -# ...
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -  - name: add back to load balancer pool
                                                                                                                                                                                                                                                                                                                    -    local_action: command /usr/bin/add_back_to_pool $inventory_hostname
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Understanding Variable Precedence

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    You have already learned about inventory host and group variables, ‘vars’, and ‘vars_files’.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    If a variable name is defined in more than one place with the same name, priority is as follows -to determine which place sets the value of the variable.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                      -
                                                                                                                                                                                                                                                                                                                    1. Variables loaded from YAML files mentioned in ‘vars_files’ in a playbook.
                                                                                                                                                                                                                                                                                                                    2. -
                                                                                                                                                                                                                                                                                                                    3. ‘vars’ as defined in the playbook.
                                                                                                                                                                                                                                                                                                                    4. -
                                                                                                                                                                                                                                                                                                                    5. facts, whether built in or custom, or variables assigned from the ‘register’ keyword.
                                                                                                                                                                                                                                                                                                                    6. -
                                                                                                                                                                                                                                                                                                                    7. variables passed to parameterized task include statements.
                                                                                                                                                                                                                                                                                                                    8. -
                                                                                                                                                                                                                                                                                                                    9. Host variables from inventory.
                                                                                                                                                                                                                                                                                                                    10. -
                                                                                                                                                                                                                                                                                                                    11. Group variables from inventory, in order of least specific group to most specific.
                                                                                                                                                                                                                                                                                                                    12. -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Therefore, if you want to set a default value for something you wish to override somewhere else, the best -place to set such a default is in a group variable.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Style Points

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Ansible playbooks are colorized. If you do not like this, set the ANSIBLE_NOCOLOR=1 environment variable.

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Ansible playbooks also look more impressive with cowsay installed, and we encourage installing this package.

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    See also

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    YAML Syntax
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Learn about YAML syntax
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Playbooks
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Review the basic playbook features
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Best Practices
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Various tips about playbooks in the real world
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Ansible Modules
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Learn about available modules
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Module Development
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Learn how to extend Ansible by writing your own modules
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Inventory & Patterns
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Learn about how to select hosts
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Github examples directory
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Complete playbook files from the github project source
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Mailing List
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Questions? Help? Ideas? Stop by the list on Google Groups
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - - -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - - - \ No newline at end of file diff --git a/docsite/search.html b/docsite/search.html deleted file mode 100644 index 8aadc33054c..00000000000 --- a/docsite/search.html +++ /dev/null @@ -1,191 +0,0 @@ - - - - - - - - - Search — Ansible Documentation - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                                                                                    - -
                                                                                                                                                                                                                                                                                                                    - - -
                                                                                                                                                                                                                                                                                                                    - -

                                                                                                                                                                                                                                                                                                                    Search

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - -

                                                                                                                                                                                                                                                                                                                    - Please activate JavaScript to enable the search - functionality. -

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    - From here you can search these documents. Enter your search - words into the box below and click "search". Note that the search - function will automatically search for all of the words. Pages - containing fewer words won't appear in the result list. -

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - - - -
                                                                                                                                                                                                                                                                                                                    - -
                                                                                                                                                                                                                                                                                                                    - -
                                                                                                                                                                                                                                                                                                                    - -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - - - \ No newline at end of file diff --git a/docsite/who_uses_ansible.html b/docsite/who_uses_ansible.html deleted file mode 100644 index 610e71bc9da..00000000000 --- a/docsite/who_uses_ansible.html +++ /dev/null @@ -1,267 +0,0 @@ - - - - - - - - - Who Uses Ansible — Ansible - SSH-Based Configuration Management & Deployment - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                                                                                    - -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Ansible Documentation

                                                                                                                                                                                                                                                                                                                    - - -
                                                                                                                                                                                                                                                                                                                    - Ansible
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Who Uses Ansible

                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    Ansible is used by all sorts of organizations from hosted web applications, media companies, universities, consultancies, and ISVs – all over the world. Some of these users include:

                                                                                                                                                                                                                                                                                                                    - ---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                                                                                                                                                                                                                                                                                                    Who They AreWhat They Do
                                                                                                                                                                                                                                                                                                                    Alta Language ServicesLanguage testing, solutions, and translation services
                                                                                                                                                                                                                                                                                                                    BashoMakers of NoSQL key-value store Riak
                                                                                                                                                                                                                                                                                                                    CatN HostingScalable Cloud Hosting
                                                                                                                                                                                                                                                                                                                    Cygate ABIT solutions from Malmö, Sweden
                                                                                                                                                                                                                                                                                                                    Dag IT Solutions“Enterprise Linux and Beyond”
                                                                                                                                                                                                                                                                                                                    Duke University EconomicsResearch and Education
                                                                                                                                                                                                                                                                                                                    The Fedora ProjectProduces the popular Linux distribution
                                                                                                                                                                                                                                                                                                                    Four Kitchens“The Drupal Experts”
                                                                                                                                                                                                                                                                                                                    LizenzfreiOpen source consulting and development, Austria
                                                                                                                                                                                                                                                                                                                    Schmooze ComCreators of Industry-Leading PBX Platforms
                                                                                                                                                                                                                                                                                                                    Scientific Computing Center, Aristotle Univ. of ThessalonikiGrid/Cloud-Based Scientific Computing
                                                                                                                                                                                                                                                                                                                    Skyline.esRealtime Photo Search Engine
                                                                                                                                                                                                                                                                                                                    SteelhouseBehavioral Commerce
                                                                                                                                                                                                                                                                                                                    Tomorrow Focus Technologies GmbHRunning some of the biggest web sites in Europe
                                                                                                                                                                                                                                                                                                                    123i.com.brFind real estate in Brazil
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    and lots of other people (you should see our Google Analytics data). Tweet at Michael DeHaan or email him to get your company or project listed here. (It’s free!)

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -

                                                                                                                                                                                                                                                                                                                    See also

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Mailing List
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Several hundred of our closest friends, great for Q&A
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    irc.freenode.net
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    #ansible IRC chat channel
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    List of Github Contributors
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    all the awesome folks who have contributed improvements to Ansible
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    Github Impact Graphs
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    week-to-week source code activity, by contributor
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - - -
                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    - - - \ No newline at end of file