Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
57c9534a
Commit
57c9534a
authored
Sep 29, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify register example
parent
e108d175
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
11 deletions
+10
-11
examples/playbooks/register_logic.yml
+10
-11
No files found.
examples/playbooks/register_logic.yml
View file @
57c9534a
...
...
@@ -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
"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment