summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/include_import/role/test_import_role.yml
blob: d45ff79bd4064c372d9662d8fd55d182f8d6c476 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
- name: Test import_role
  hosts: testhost

  vars:
    run_role: yes
    do_not_run_role: no
    role_name: role1
    test_var: templating test in playbook
    role_vars:
      where_am_i_defined: in the playbook
    entire_task:
      include_role:
        name: role1

  tasks:
    - name: Test basic role import
      import_role:
        name: role1

    - name: Assert that basic include works
      assert:
        that:
          - _role1_result.msg == 'In role1'

    - name: Test conditional role include
      import_role:
        name: role1
        tasks_from: canary1.yml
      when: run_role

    - name: Assert that role ran
      assert:
        that:
          - role1_canary1 == 'r1c1'

    - name: Test conditional role import that should be skipped
      import_role:
        name: role1
        tasks_from: canary2.yml
      when: do_not_run_role

    - name: Assert that role did not run
      assert:
        that:
          - role1_canary2 is not defined

    # FIXME We expect this to fail, but I'm not sure how best to test for
    # syntax level failures.
    #
    # - name: Test role import with a loop
    #   import_role:
    #     name: "{{ item }}"
    #   register: loop_test
    #   with_items:
    #     - role1
    #     - role3
    #     - role2

    - name: Test importing a task file from a role
      import_role:
        name: role1
        tasks_from: tasks.yml

    - name: Test importing vars file and tasks file from a role
      import_role:
        name: role3
        tasks_from: vartest.yml
        vars_from: role3vars.yml

    - name: Assert that variables defined in previous task are available to play
      assert:
        that:
          - role3_default == 'defined in role3/defaults/main.yml'
          - role3_main == 'defined in role3/vars/main.yml'
          - role3_var == 'defined in role3/vars/role3vars.yml'
      ignore_errors: yes

    - name: Test using a play variable for role name
      import_role:
        name: "{{ role_name }}"

    # FIXME Trying to use a host_var here causes play execution to fail because
    # the variable is undefined.
    #
    # - name: Test using a host variable for role name
    #   import_role:
    #     name: "{{ host_var_role_name }}"

    - name: Pass variable to role
      import_role:
        name: role1
        tasks_from: vartest.yml
      vars:
        where_am_i_defined: in the task

    ## FIXME Currently failing
    ## ERROR! Vars in a IncludeRole must be specified as a dictionary, or a list of dictionaries
    # - name: Pass all variables in a variable to role
    #   import_role:
    #     name: role1
    #     tasks_from: vartest.yml
    #   vars: "{{ role_vars }}"

    - name: Pass templated variable to a role
      import_role:
        name: role1
        tasks_from: vartest.yml
      vars:
        where_am_i_defined: "{{ test_var }}"

    # FIXME This fails with the following error:
    # The module {u'import_role': {u'name': u'role1'}} was not found in configured module paths.
    #
    - name: Include an entire task
      action:
        module: "{{ entire_task }}"
      tags:
        - never

    - block:
        - name: Include a role that will fail
          import_role:
            name: role1
            tasks_from: fail.yml

      rescue:
        - name: Include a role inside rescue
          import_role:
            name: role2

      always:
        - name: Include role inside always
          import_role:
            name: role3

    - name: Test delegate_to handler is delegated
      import_role:
        name: delegated_handler
      delegate_to: localhost