Skip to content

Commit

Permalink
Simplify register example
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdehaan committed Sep 29, 2012
1 parent e108d17 commit 57c9534
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions examples/playbooks/register_logic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@
tasks:

# it is possible to save the result of any command in a named register. This variable will be made
# available to tasks and templates made further down in the execution flow. Here we save the result
# of a simple 'cat' command in a variable called 'motd_contents'
# available to tasks and templates made further down in the execution flow.

- action: shell cat /etc/motd
register: motd_contents
- action: shell grep hi /etc/motd
ignore_errors: True
register: motd_result

# and here we access the register. Note that motd_contents as a variable is structured data because
# and here we access the register. Note that variable is structured data because
# it is a return from the command module. The shell module makes available variables such as
# as 'stdout', 'stderr', and 'rc'. Here's a rather trivial example that runs an arbitrary step
# if and only if the motd file contained the word 'hi'. Remember that only_if statements are
# Python expressions. This is as complicated as Ansible syntax is going to get, and the only
# time python really seeps into ansible's language.

# as 'stdout', 'stderr', and 'rc'.

# here we run the next action only if the previous grep returned true

- action: shell echo "motd contains the word hi"
only_if: "'${motd_contents.stdout}'.find('hi') != -1"
only_if: "${motd_result.rc} == 0"


0 comments on commit 57c9534

Please sign in to comment.