summaryrefslogtreecommitdiffstats
path: root/awx_collection/tests/integration/targets/role/tasks/main.yml
blob: 03beed965900f5d90bd4088960a74a32a5ffe49f (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
---
- name: Generate a test id
  set_fact:
    test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"

- name: Generate names
  set_fact:
    username: "AWX-Collection-tests-tower_role-user-{{ test_id }}"
    project_name: "AWX-Collection-tests-tower_role-project-1-{{ test_id }}"
    jt1: "AWX-Collection-tests-tower_role-jt1-{{ test_id }}"
    jt2: "AWX-Collection-tests-tower_role-jt2-{{ test_id }}"
    wfjt_name: "AWX-Collection-tests-tower_role-project-wfjt-{{ test_id }}"

- block:
    - name: Create a User
      user:
        first_name: Joe
        last_name: User
        username: "{{ username }}"
        password: "{{ 65535 | random | to_uuid }}"
        email: joe@example.org
        state: present
      register: result

    - assert:
        that:
          - "result is changed"

    - name: Create a project
      project:
        name: "{{ project_name }}"
        organization: Default
        scm_type: git
        scm_url: https://github.com/ansible/test-playbooks
        wait: true
      register: project_info

    - assert:
        that:
          - project_info is changed

    - name: Create job templates
      tower_job_template:
        name: "{{ item }}"
        project: "{{ project_name }}"
        inventory: "Demo Inventory"
        playbook: become.yml
      with_items:
        - jt1
        - jt2
      register: result

    - assert:
        that:
          - "result is changed"

    - name: Add Joe to the update role of the default Project with lookup Organization
      role:
        user: "{{ username }}"
        role: update
        lookup_organization: Default
        project: "Demo Project"
        state: "{{ item }}"
      register: result
      with_items:
        - "present"
        - "absent"

    - assert:
        that:
          - "result is changed"

    - name: Add Joe to the new project by ID
      role:
        user: "{{ username }}"
        role: update
        project: "{{ project_info['id'] }}"
        state: "{{ item }}"
      register: result
      with_items:
        - "present"
        - "absent"

    - assert:
        that:
          - "result is changed"

    - name: Create a workflow
      tower_workflow_job_template:
        name: test-role-workflow
        organization: Default
        state: present

    - name: Add Joe to workflow execute role
      role:
        user: "{{ username }}"
        role: execute
        workflow: test-role-workflow
        job_templates:
          - jt1
          - jt2
        state: present
      register: result

    - assert:
        that:
          - "result is changed"

    - name: Add Joe to workflow execute role, no-op
      role:
        user: "{{ username }}"
        role: execute
        workflow: test-role-workflow
        state: present
      register: result

    - assert:
        that:
          - "result is not changed"

    - name: Add Joe to workflow approve role
      role:
        user: "{{ username }}"
        role: approval
        workflow: test-role-workflow
        state: present
      register: result

    - assert:
        that:
          - "result is changed"

  always:
    - name: Delete a User
      user:
        username: "{{ username }}"
        email: joe@example.org
        state: absent
      register: result

    - name: Delete job templates
      tower_job_template:
        name: "{{ item }}"
        project: "{{ project_name }}"
        inventory: "Demo Inventory"
        playbook: debug.yml
        state: absent
      with_items:
        - jt1
        - jt2
      register: result

    - name: Delete the project
      project:
        name: "{{ project_name }}"
        organization: Default
        state: absent
      register: result