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
cabd40b0
Commit
cabd40b0
authored
May 03, 2013
by
Kahlil (Kal) Hodgson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add docs for 'when: var is defined' idiom
parent
2cf30148
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
1 deletions
+14
-1
docsite/latest/rst/playbooks2.rst
+14
-1
docsite/latest/searchindex.js
+0
-0
No files found.
docsite/latest/rst/playbooks2.rst
View file @
cabd40b0
...
@@ -279,6 +279,19 @@ As a reminder, to see what derived variables are available, you can do::
...
@@ -279,6 +279,19 @@ As a reminder, to see what derived variables are available, you can do::
Variables defined in the playbooks or inventory can also be used.
Variables defined in the playbooks or inventory can also be used.
If a required variable has not been set, you can skip or fail using Jinja2's
`defined` test. For example::
tasks:
- shell: echo "I've got '{{ foo }}' and am not afraid to use it!"
when: foo is defined
- fail: msg="Bailing out: this play requires 'bar'"
when: bar is not defined
This is especially useful in combination with the conditional import of vars
files (see below).
It's also easy to provide your own facts if you want, which is covered in :doc:`moduledev`. To run them, just
It's also easy to provide your own facts if you want, which is covered in :doc:`moduledev`. To run them, just
make a call to your own custom fact gathering module at the top of your list of tasks, and variables returned
make a call to your own custom fact gathering module at the top of your list of tasks, and variables returned
there will be accessible to future tasks::
there will be accessible to future tasks::
...
@@ -288,7 +301,7 @@ there will be accessible to future tasks::
...
@@ -288,7 +301,7 @@ there will be accessible to future tasks::
action: site_facts
action: site_facts
- action: command echo {{ my_custom_fact_can_be_used_now }}
- action: command echo {{ my_custom_fact_can_be_used_now }}
One common useful trick with
only_if
is to key off the changed result of a last command. As an example::
One common useful trick with
`when`
is to key off the changed result of a last command. As an example::
tasks:
tasks:
- action: template src=/templates/foo.j2 dest=/etc/foo.conf
- action: template src=/templates/foo.j2 dest=/etc/foo.conf
...
...
docsite/latest/searchindex.js
View file @
cabd40b0
This diff is collapsed.
Click to expand it.
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