mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
Merge pull request #363 from jhoekx/template-only-if
Fix correct variable expansion in includes only_if.
This commit is contained in:
commit
f8807da57b
6 changed files with 61 additions and 6 deletions
|
@ -172,3 +172,28 @@ class TestPlaybook(unittest.TestCase):
|
|||
print data
|
||||
assert data.find("ears") != -1, "template success"
|
||||
|
||||
def test_includes(self):
|
||||
pb = os.path.join(self.test_dir, 'playbook_includes.yml')
|
||||
actual = self._run(pb)
|
||||
|
||||
for i, event in enumerate(EVENTS):
|
||||
print "EVENT %s"%(i)
|
||||
print event
|
||||
|
||||
if i == 6:
|
||||
assert 'blue' in event[1][1]['cmd']
|
||||
|
||||
if i == 8:
|
||||
assert 'quack' in event[1][1]['cmd']
|
||||
|
||||
if i == 10:
|
||||
assert 'RAN' in event[1][1]['cmd']
|
||||
|
||||
if i == 12:
|
||||
assert 'RAN' in event[1][1]['cmd']
|
||||
|
||||
if i == 14:
|
||||
assert 'red' in event[1][1]['cmd']
|
||||
|
||||
if i == 18 or i == 20:
|
||||
assert 'skipped' in event[0]
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
---
|
||||
duck: quack
|
||||
cow: moo
|
||||
extguard: " '$favcolor' == 'blue' "
|
||||
|
|
14
test/playbook_included.yml
Normal file
14
test/playbook_included.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
- name: test vars
|
||||
action: shell echo $favcolor
|
||||
|
||||
- name: test vars_files
|
||||
action: shell echo $duck
|
||||
|
||||
- name: test vars condition
|
||||
action: shell echo RAN
|
||||
only_if: $guard
|
||||
|
||||
- name: test vars_files condition
|
||||
action: shell echo RAN
|
||||
only_if: $extguard
|
15
test/playbook_includes.yml
Normal file
15
test/playbook_includes.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
# Test correct variable expansion in included files and only if
|
||||
- hosts: all
|
||||
vars:
|
||||
favcolor: "blue"
|
||||
guard: ' "$favcolor" == "blue" '
|
||||
vars_files:
|
||||
- common_vars.yml
|
||||
|
||||
tasks:
|
||||
|
||||
- include: playbook_included.yml
|
||||
|
||||
# test overrides of variables
|
||||
- include: playbook_included.yml favcolor=red
|
Loading…
Add table
Add a link
Reference in a new issue