Here is what a basic task looks like. As with most
modules, the service module takes key=value arguments:
- name: make
sure apache is running
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
them work as simply as you would expect:
tasks:
- name: enable
selinux
command: /sbin/setenforce
1
The command and shell module care about return codes,
so if you have a command whose successful exit code is not zero, you may wish
to do this:
tasks:
- name: run
this command and ignore the result
shell:
/usr/bin/somecommand || /bin/true
Or this:
tasks:
- name: run
this command and ignore the result
shell:
/usr/bin/somecommand
ignore_errors: True
If the action line is getting too long for comfort you
can break it on a space and indent any continuation lines:
tasks:
- name: Copy
ansible inventory file to client
copy:
src=/etc/ansible/hosts dest=/etc/ansible/hosts
owner=root group=root mode=0644
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 }}
template:
src=somefile.j2 dest=/etc/httpd/conf.d/{{ vhost }}
To check the syntax of a playbook, use
ansible-playbook with the --syntax-check flag. This will run the playbook file
through the parser to ensure its included files, roles, etc. have no syntax
problems.
Look at the bottom of the playbook execution for a summary
of the nodes that were targeted and how they performed. General failures and
fatal “unreachable” communication attempts are kept separate 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.
No comments:
Post a Comment