Commit a6b4b9a7 by Michael DeHaan

Show more whitespace throughout playbook examples to encourage better standards…

Show more whitespace throughout playbook examples to encourage better standards in first playbooks folks write.
parent 4b281ca5
...@@ -44,9 +44,12 @@ Accelerated mode offers several improvements over the (deprecated) original fire ...@@ -44,9 +44,12 @@ Accelerated mode offers several improvements over the (deprecated) original fire
In order to use accelerated mode, simply add `accelerate: true` to your play:: In order to use accelerated mode, simply add `accelerate: true` to your play::
--- ---
- hosts: all - hosts: all
accelerate: true accelerate: true
tasks: tasks:
- name: some task - name: some task
command: echo {{ item }} command: echo {{ item }}
with_items: with_items:
...@@ -57,6 +60,7 @@ In order to use accelerated mode, simply add `accelerate: true` to your play:: ...@@ -57,6 +60,7 @@ In order to use accelerated mode, simply add `accelerate: true` to your play::
If you wish to change the port Ansible will use for the accelerated connection, just add the `accelerated_port` option:: If you wish to change the port Ansible will use for the accelerated connection, just add the `accelerated_port` option::
--- ---
- hosts: all - hosts: all
accelerate: true accelerate: true
# default port is 5099 # default port is 5099
......
...@@ -16,9 +16,12 @@ and how frequently you would like to poll for status. The default ...@@ -16,9 +16,12 @@ 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`:: poll value is 10 seconds if you do not specify a value for `poll`::
--- ---
- hosts: all - hosts: all
remote_user: root remote_user: root
tasks: tasks:
- name: simulate long running op (15 sec), wait for up to 45, poll every 5 - name: simulate long running op (15 sec), wait for up to 45, poll every 5
command: /bin/sleep 15 command: /bin/sleep 15
async: 45 async: 45
...@@ -33,9 +36,12 @@ Alternatively, if you do not need to wait on the task to complete, you may ...@@ -33,9 +36,12 @@ 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:: "fire and forget" by specifying a poll value of 0::
--- ---
- hosts: all - hosts: all
remote_user: root remote_user: root
tasks: tasks:
- name: simulate long running op, allow to run for 45, fire and forget - name: simulate long running op, allow to run for 45, fire and forget
command: /bin/sleep 15 command: /bin/sleep 15
async: 45 async: 45
......
...@@ -305,6 +305,7 @@ This makes a dynamic group of hosts matching certain criteria, even if that grou ...@@ -305,6 +305,7 @@ This makes a dynamic group of hosts matching certain criteria, even if that grou
# talk to all hosts just so we can learn about them # talk to all hosts just so we can learn about them
- hosts: all - hosts: all
tasks: tasks:
- group_by: key={{ ansible_distribution }} - group_by: key={{ ansible_distribution }}
...@@ -312,6 +313,7 @@ This makes a dynamic group of hosts matching certain criteria, even if that grou ...@@ -312,6 +313,7 @@ This makes a dynamic group of hosts matching certain criteria, even if that grou
- hosts: CentOS - hosts: CentOS
gather_facts: False gather_facts: False
tasks: tasks:
- # tasks that only happen on CentOS go here - # tasks that only happen on CentOS go here
......
...@@ -71,10 +71,12 @@ outage windows. Using this with the 'serial' keyword to control the number of h ...@@ -71,10 +71,12 @@ outage windows. Using this with the 'serial' keyword to control the number of h
a good idea:: a good idea::
--- ---
- hosts: webservers - hosts: webservers
serial: 5 serial: 5
tasks: tasks:
- name: take out of load balancer pool - name: take out of load balancer pool
command: /usr/bin/take_out_of_pool {{ inventory_hostname }} command: /usr/bin/take_out_of_pool {{ inventory_hostname }}
delegate_to: 127.0.0.1 delegate_to: 127.0.0.1
...@@ -87,13 +89,14 @@ a good idea:: ...@@ -87,13 +89,14 @@ a good idea::
delegate_to: 127.0.0.1 delegate_to: 127.0.0.1
These commands will run on 127.0.0.1, which is the machine running Ansible. There is also a shorthand syntax that These commands will run on 127.0.0.1, which is the machine running Ansible. There is also a shorthand syntax that you can use on a per-task basis: 'local_action'. Here is the same playbook as above, but using the shorthand syntax for delegating to 127.0.0.1::
you can use on a per-task basis: 'local_action'. Here is the same playbook as above, but using the shorthand
syntax for delegating to 127.0.0.1::
--- ---
# ... # ...
tasks: tasks:
- name: take out of load balancer pool - name: take out of load balancer pool
local_action: command /usr/bin/take_out_of_pool {{ inventory_hostname }} local_action: command /usr/bin/take_out_of_pool {{ inventory_hostname }}
...@@ -108,6 +111,7 @@ Here is an example:: ...@@ -108,6 +111,7 @@ Here is an example::
--- ---
# ... # ...
tasks: tasks:
- name: recursively copy files from management server to target - name: recursively copy files from management server to target
local_action: command rsync -a /path/to/files {{ inventory_hostname }}:/path/to/target/ local_action: command rsync -a /path/to/files {{ inventory_hostname }}:/path/to/target/
......
...@@ -21,7 +21,9 @@ Contents can be read off the filesystem as follows:: ...@@ -21,7 +21,9 @@ Contents can be read off the filesystem as follows::
- hosts: all - hosts: all
vars: vars:
contents: "{{ lookup('file', '/etc/foo.txt') }}" contents: "{{ lookup('file', '/etc/foo.txt') }}"
tasks: tasks:
- debug: msg="the value of foo.txt is {{ contents }}" - debug: msg="the value of foo.txt is {{ contents }}"
.. _password_lookup: .. _password_lookup:
...@@ -128,6 +130,7 @@ template):: ...@@ -128,6 +130,7 @@ template)::
motd_value: "{{ lookup('file', '/etc/motd') }}" motd_value: "{{ lookup('file', '/etc/motd') }}"
tasks: tasks:
- debug: msg="motd value is {{ motd_value }}" - debug: msg="motd value is {{ motd_value }}"
.. seealso:: .. seealso::
......
...@@ -15,8 +15,10 @@ Here is a most basic example:: ...@@ -15,8 +15,10 @@ Here is a most basic example::
--- ---
- hosts: all - hosts: all
remote_user: root remote_user: root
vars: vars:
from: "camelot" from: "camelot"
vars_prompt: vars_prompt:
name: "what is your name?" name: "what is your name?"
quest: "what is your quest?" quest: "what is your quest?"
...@@ -27,6 +29,7 @@ provide a default value that can be overridden. This can be accomplished using ...@@ -27,6 +29,7 @@ provide a default value that can be overridden. This can be accomplished using
the default argument:: the default argument::
vars_prompt: vars_prompt:
- name: "release_version" - name: "release_version"
prompt: "Product release version" prompt: "Product release version"
default: "1.0" default: "1.0"
...@@ -35,9 +38,11 @@ An alternative form of vars_prompt allows for hiding input from the user, and ma ...@@ -35,9 +38,11 @@ An alternative form of vars_prompt allows for hiding input from the user, and ma
some other options, but otherwise works equivalently:: some other options, but otherwise works equivalently::
vars_prompt: vars_prompt:
- name: "some_password" - name: "some_password"
prompt: "Enter password" prompt: "Enter password"
private: yes private: yes
- name: "release_version" - name: "release_version"
prompt: "Product release version" prompt: "Product release version"
private: no private: no
...@@ -46,6 +51,7 @@ If `Passlib <http://pythonhosted.org/passlib/>`_ is installed, vars_prompt can a ...@@ -46,6 +51,7 @@ If `Passlib <http://pythonhosted.org/passlib/>`_ is installed, vars_prompt can a
entered value so you can use it, for instance, with the user module to define a password:: entered value so you can use it, for instance, with the user module to define a password::
vars_prompt: vars_prompt:
- name: "my_password2" - name: "my_password2"
prompt: "Enter password2" prompt: "Enter password2"
private: yes private: yes
......
...@@ -42,15 +42,18 @@ A task include file simply contains a flat list of tasks, like so:: ...@@ -42,15 +42,18 @@ A task include file simply contains a flat list of tasks, like so::
--- ---
# possibly saved as tasks/foo.yml # possibly saved as tasks/foo.yml
- name: placeholder foo - name: placeholder foo
command: /bin/foo command: /bin/foo
- name: placeholder bar - name: placeholder bar
command: /bin/bar command: /bin/bar
Include directives look like this, and can be mixed in with regular tasks in a playbook:: Include directives look like this, and can be mixed in with regular tasks in a playbook::
tasks: tasks:
- include: tasks/foo.yml
- include: tasks/foo.yml
You can also pass variables into includes. We call this a 'parameterized include'. You can also pass variables into includes. We call this a 'parameterized include'.
...@@ -120,7 +123,9 @@ For example:: ...@@ -120,7 +123,9 @@ For example::
- name: this is a play at the top level of a file - name: this is a play at the top level of a file
hosts: all hosts: all
remote_user: root remote_user: root
tasks: tasks:
- name: say hi - name: say hi
tags: foo tags: foo
shell: echo "hi..." shell: echo "hi..."
...@@ -211,6 +216,7 @@ the roles are evaluated first. ...@@ -211,6 +216,7 @@ the roles are evaluated first.
Also, should you wish to parameterize roles, by adding variables, you can do so, like this:: Also, should you wish to parameterize roles, by adding variables, you can do so, like this::
--- ---
- hosts: webservers - hosts: webservers
roles: roles:
- common - common
...@@ -220,6 +226,7 @@ Also, should you wish to parameterize roles, by adding variables, you can do so, ...@@ -220,6 +226,7 @@ Also, should you wish to parameterize roles, by adding variables, you can do so,
While it's probably not something you should do often, you can also conditionally apply roles like so:: While it's probably not something you should do often, you can also conditionally apply roles like so::
--- ---
- hosts: webservers - hosts: webservers
roles: roles:
- { role: some_role, when: "ansible_os_family == 'RedHat'" } - { role: some_role, when: "ansible_os_family == 'RedHat'" }
...@@ -230,6 +237,7 @@ the documentation. ...@@ -230,6 +237,7 @@ the documentation.
Finally, you may wish to assign tags to the roles you specify. You can do so inline::: Finally, you may wish to assign tags to the roles you specify. You can do so inline:::
--- ---
- hosts: webservers - hosts: webservers
roles: roles:
- { role: foo, tags: ["bar", "baz"] } - { role: foo, tags: ["bar", "baz"] }
...@@ -240,13 +248,18 @@ If the play still has a 'tasks' section, those tasks are executed after roles ar ...@@ -240,13 +248,18 @@ If the play still has a 'tasks' section, those tasks are executed after roles ar
If you want to define certain tasks to happen before AND after roles are applied, you can do this:: If you want to define certain tasks to happen before AND after roles are applied, you can do this::
--- ---
- hosts: webservers - hosts: webservers
pre_tasks: pre_tasks:
- shell: echo 'hello' - shell: echo 'hello'
roles: roles:
- { role: some_role } - { role: some_role }
tasks: tasks:
- shell: echo 'still busy' - shell: echo 'still busy'
post_tasks: post_tasks:
- shell: echo 'goodbye' - shell: echo 'goodbye'
......
...@@ -136,6 +136,7 @@ Filters Often Used With Conditionals ...@@ -136,6 +136,7 @@ Filters Often Used With Conditionals
The following tasks are illustrative of how filters can be used with conditionals:: The following tasks are illustrative of how filters can be used with conditionals::
tasks: tasks:
- shell: /usr/bin/foo - shell: /usr/bin/foo
register: result register: result
ignore_errors: True ignore_errors: True
...@@ -691,13 +692,16 @@ the main playbook. ...@@ -691,13 +692,16 @@ the main playbook.
You can do this by using an external variables file, or files, just like this:: You can do this by using an external variables file, or files, just like this::
--- ---
- hosts: all - hosts: all
remote_user: root remote_user: root
vars: vars:
favcolor: blue favcolor: blue
vars_files: vars_files:
- /vars/external_vars.yml - /vars/external_vars.yml
tasks: tasks:
- name: this is just a placeholder - name: this is just a placeholder
command: /bin/echo foo command: /bin/echo foo
...@@ -731,8 +735,10 @@ This is useful, for, among other things, setting the hosts group or the user for ...@@ -731,8 +735,10 @@ This is useful, for, among other things, setting the hosts group or the user for
Example:: Example::
--- ---
- remote_user: '{{ user }}'
hosts: '{{ hosts }}' - hosts: '{{ hosts }}'
remote_user: '{{ user }}'
tasks: tasks:
- ... - ...
...@@ -765,12 +771,15 @@ As an example, the name of the Apache package may be different between CentOS an ...@@ -765,12 +771,15 @@ As an example, the name of the Apache package may be different between CentOS an
but it is easily handled with a minimum of syntax in an Ansible Playbook:: but it is easily handled with a minimum of syntax in an Ansible Playbook::
--- ---
- hosts: all - hosts: all
remote_user: root remote_user: root
vars_files: vars_files:
- "vars/common.yml" - "vars/common.yml"
- [ "vars/{{ ansible_os_family }}.yml", "vars/os_defaults.yml" ] - [ "vars/{{ ansible_os_family }}.yml", "vars/os_defaults.yml" ]
tasks: tasks:
- name: make sure apache is running - name: make sure apache is running
service: name={{ apache }} state=running service: name={{ apache }} state=running
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment