summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/module_defaults/tasks/main.yml
blob: 747c2f9233f04c3e7033880378b11de9664430fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
- 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
        ping:
          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!"