2018-04-05 17:44:51 +02:00
|
|
|
- name: main block
|
|
|
|
vars:
|
|
|
|
test_file: /tmp/ansible-test.module_defaults.foo
|
|
|
|
module_defaults:
|
|
|
|
debug:
|
|
|
|
msg: test default
|
|
|
|
file:
|
|
|
|
path: '{{ test_file }}'
|
|
|
|
block:
|
|
|
|
- debug:
|
|
|
|
register: foo
|
|
|
|
|
|
|
|
- name: test that 'debug' task used default 'msg' param
|
|
|
|
assert:
|
|
|
|
that: foo.msg == "test default"
|
|
|
|
|
|
|
|
- name: remove test file
|
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: touch test file
|
|
|
|
file:
|
|
|
|
state: touch
|
|
|
|
|
|
|
|
- name: stat test file
|
|
|
|
stat:
|
|
|
|
path: '{{ test_file }}'
|
|
|
|
register: foo
|
|
|
|
|
|
|
|
- name: check that test file exists
|
|
|
|
assert:
|
|
|
|
that: foo.stat.exists
|
|
|
|
|
|
|
|
- name: remove test file
|
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: test that module defaults from parent are inherited and merged
|
|
|
|
module_defaults:
|
|
|
|
# Meaningless values to make sure that 'module_defaults' gets
|
|
|
|
# evaluated for this block
|
|
|
|
foo:
|
|
|
|
bar: baz
|
|
|
|
block:
|
|
|
|
- debug:
|
|
|
|
register: foo
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: foo.msg == "test default"
|
|
|
|
|
|
|
|
- name: test that we can override module defaults inherited from parent
|
|
|
|
module_defaults:
|
|
|
|
debug:
|
|
|
|
msg: "different test message"
|
|
|
|
block:
|
|
|
|
- debug:
|
|
|
|
register: foo
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: foo.msg == "different test message"
|
|
|
|
|
|
|
|
- name: test that module defaults inherited from parent can be removed
|
|
|
|
module_defaults:
|
|
|
|
debug: {}
|
|
|
|
block:
|
|
|
|
- debug:
|
|
|
|
register: foo
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
foo.msg == "Hello world!"
|
|
|
|
|
|
|
|
- name: test that module defaults can be overridden by module params
|
|
|
|
block:
|
|
|
|
- debug:
|
|
|
|
msg: another test message
|
|
|
|
register: foo
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
foo.msg == "another test message"
|
|
|
|
|
|
|
|
- debug:
|
|
|
|
msg: '{{ omit }}'
|
|
|
|
register: foo
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
foo.msg == "Hello world!"
|
2018-08-23 03:33:27 +02:00
|
|
|
- name: Module group defaults block
|
|
|
|
module_defaults:
|
2020-02-11 22:14:26 +01:00
|
|
|
group/test:
|
|
|
|
arg1: "test1"
|
|
|
|
arg2: "test2"
|
2018-08-23 03:33:27 +02:00
|
|
|
block:
|
2020-02-11 22:14:26 +01:00
|
|
|
- test_module_defaults:
|
|
|
|
register: result
|
2018-08-23 03:33:27 +02:00
|
|
|
- assert:
|
|
|
|
that:
|
2020-02-11 22:14:26 +01:00
|
|
|
- "result.test_module_defaults.arg1 == 'test1'"
|
|
|
|
- "result.test_module_defaults.arg2 == 'test2'"
|
|
|
|
- "result.test_module_defaults.arg3 == 'default3'"
|
2018-08-23 03:33:27 +02:00
|
|
|
- name: Module group defaults block
|
|
|
|
module_defaults:
|
2020-02-11 22:14:26 +01:00
|
|
|
group/test:
|
|
|
|
arg1: "test1"
|
|
|
|
arg2: "test2"
|
|
|
|
arg3: "test3"
|
2018-08-23 03:33:27 +02:00
|
|
|
block:
|
2020-02-11 22:14:26 +01:00
|
|
|
- test_module_defaults:
|
|
|
|
register: result
|
2018-08-23 03:33:27 +02:00
|
|
|
- assert:
|
|
|
|
that:
|
2020-02-11 22:14:26 +01:00
|
|
|
- "result.test_module_defaults.arg1 == 'test1'"
|
|
|
|
- "result.test_module_defaults.arg2 == 'test2'"
|
|
|
|
- "result.test_module_defaults.arg3 == 'test3'"
|