summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAren <7918248+funixz@users.noreply.github.com>2017-09-14 05:06:33 +0200
committerJordan Borean <jborean93@gmail.com>2017-09-14 05:06:33 +0200
commit60d9a12efd28dc1a9055cefe55af0e7b0c16b2a8 (patch)
treec5c6affb901439bcac58cdc8fd7c9344b973966e
parentfix broken rpm link (#29667) (diff)
downloadansible-60d9a12efd28dc1a9055cefe55af0e7b0c16b2a8.tar.xz
ansible-60d9a12efd28dc1a9055cefe55af0e7b0c16b2a8.zip
swapped out key-value pairs for multi-line YML (#30277)
-rw-r--r--docs/docsite/rst/playbooks_intro.rst48
1 files changed, 36 insertions, 12 deletions
diff --git a/docs/docsite/rst/playbooks_intro.rst b/docs/docsite/rst/playbooks_intro.rst
index 20cf57bcc7..12a2b7109f 100644
--- a/docs/docsite/rst/playbooks_intro.rst
+++ b/docs/docsite/rst/playbooks_intro.rst
@@ -114,18 +114,26 @@ the web servers, and then the database servers. For example::
tasks:
- name: ensure apache is at the latest version
- yum: name=httpd state=latest
+ yum:
+ name: httpd
+ state: latest
- name: write the apache config file
- template: src=/srv/httpd.j2 dest=/etc/httpd.conf
+ template:
+ src: /srv/httpd.j2
+ dest: /etc/httpd.conf
- hosts: databases
remote_user: root
tasks:
- name: ensure postgresql is at the latest version
- yum: name=postgresql state=latest
+ yum:
+ name: postgresql
+ state: latest
- name: ensure that postgresql is started
- service: name=postgresql state=started
+ service:
+ name: postgresql
+ state: started
You can use this method to switch between the host group you're targeting,
the username logging into the remote servers, whether to sudo or not, and so
@@ -187,7 +195,9 @@ You can also use become on a particular task instead of the whole play::
- hosts: webservers
remote_user: yourname
tasks:
- - service: name=nginx state=started
+ - service:
+ name: nginx
+ state: started
become: yes
become_method: sudo
@@ -302,7 +312,9 @@ the service module takes ``key=value`` arguments::
tasks:
- name: make sure apache is running
- service: name=httpd state=started
+ service:
+ name: httpd
+ state: started
The **command** and **shell** modules are the only modules that just take a list
of arguments and don't use the ``key=value`` form. This makes
@@ -340,7 +352,9 @@ a variable called ``vhost`` in the ``vars`` section, you could do this::
tasks:
- name: create a virtual host file for {{ vhost }}
- template: src=somefile.j2 dest=/etc/httpd/conf.d/{{ vhost }}
+ template:
+ src: somefile.j2
+ dest: /etc/httpd/conf.d/{{ vhost }}
Those same variables are usable in templates, which we'll get to later.
@@ -384,7 +398,9 @@ 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
- template: src=template.j2 dest=/etc/foo.conf
+ template:
+ src: template.j2
+ dest: /etc/foo.conf
notify:
- restart memcached
- restart apache
@@ -402,18 +418,26 @@ Here's an example handlers section::
handlers:
- name: restart memcached
- service: name=memcached state=restarted
+ service:
+ name: memcached
+ state: restarted
- name: restart apache
- service: name=apache state=restarted
+ service:
+ name: apache
+ state: restarted
As of Ansible 2.2, handlers can also "listen" to generic topics, and tasks can notify those topics as follows::
handlers:
- name: restart memcached
- service: name=memcached state=restarted
+ service:
+ name: memcached
+ state: restarted
listen: "restart web services"
- name: restart apache
- service: name=apache state=restarted
+ service:
+ name: apache
+ state:restarted
listen: "restart web services"
tasks: