diff options
author | Michael DeHaan <michael.dehaan@gmail.com> | 2013-02-17 15:06:17 -0500 |
---|---|---|
committer | Michael DeHaan <michael.dehaan@gmail.com> | 2013-02-17 15:06:17 -0500 |
commit | 7da9992110aac38f6b0af126c4662fb51a80be9e (patch) | |
tree | 64e8b6aea9f17f5691461363b9e8cb6d36d1358c /examples/playbooks | |
parent | b63bf62b13a4c898d9cda42b5e61760d0f80b6f2 (diff) | |
download | ansible-7da9992110aac38f6b0af126c4662fb51a80be9e.tar.gz |
Add complex arguments example
Diffstat (limited to 'examples/playbooks')
-rw-r--r-- | examples/playbooks/complex_args.yml | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/examples/playbooks/complex_args.yml b/examples/playbooks/complex_args.yml new file mode 100644 index 0000000000..16fd6364d0 --- /dev/null +++ b/examples/playbooks/complex_args.yml @@ -0,0 +1,55 @@ +--- + +# this is a bit of an advanced topic. +# +# generally Ansible likes to pass simple key=value arguments to modules. It occasionally comes up though +# that you might want to write a module that takes COMPLEX arguments, like lists and dictionaries. +# +# happen, at least right now, it should be a Python module, so it can leverage some common code in Ansible that +# makes this easy. If you write a non-Python module, you can still pass data across, but only hashes that +# do not contain lists or other hashes. If you write the Python module, you can do anything. +# +# note that if you were to use BOTH the key=value form and the 'args' form for passing data in, the key=value +# parameters take a higher priority, so you can use them for defaults, which can be useful. + +- hosts: all + user: root + gather_facts: no + + vars: + defaults: + state: stopped + complex: + ghostbusters: [ 'egon', 'ray', 'peter', 'winston' ] + mice: [ 'pinky', 'brain', 'snowball', 'larry' ] + + tasks: + + - name: this is the basic way data passing works for any module + action: ping data='Hi Mom' + + - name: of course this can also be written like so, which is shorter + ping: data='Hi Mom' + + - name: but what if you have a complex module that needs complicated data? + action: ping + args: + data: + moo: cow + asdf: [1,2,3,4] + + - name: can we make that cleaner? sure! + action: ping + args: { data: $complex } + + - name: or if you prefer... this is equivalent + action: ping + args: + data: $complex + + - name: here is an example of how it works with defaults, notice the key=value format wins + action: service name=httpd state=running + args: $defaults + + + |