mirror of
https://github.com/ansible/awx.git
synced 2026-02-16 18:50:04 -03:30
* Fix collection task breaking collection ci checks * Patch ansible.module_utils.basic._ANSIBLE_PROFILE directly * Conditionalize other santity assertions * Remove added blank lines and identifier from Fail if absent and no identifier set
301 lines
7.4 KiB
YAML
301 lines
7.4 KiB
YAML
---
|
|
- name: Generate a test id
|
|
ansible.builtin.set_fact:
|
|
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
|
|
when: test_id is not defined
|
|
|
|
- name: Generate names
|
|
ansible.builtin.set_fact:
|
|
username: "AWX-Collection-tests-role-user-{{ test_id }}"
|
|
project_name: "AWX-Collection-tests-role-project-1-{{ test_id }}"
|
|
jt1: "AWX-Collection-tests-role-jt1-{{ test_id }}"
|
|
jt2: "AWX-Collection-tests-role-jt2-{{ test_id }}"
|
|
wfjt_name: "AWX-Collection-tests-role-project-wfjt-{{ test_id }}"
|
|
team_name: "AWX-Collection-tests-team-team-{{ test_id }}"
|
|
team2_name: "AWX-Collection-tests-team-team-{{ test_id }}2"
|
|
org2_name: "AWX-Collection-tests-organization-{{ test_id }}2"
|
|
|
|
- name: Main block for user creation
|
|
block:
|
|
|
|
- name: Create a user with a valid sanitized name
|
|
awx.awx.user:
|
|
username: "{{ username }}"
|
|
password: "{{ 65535 | random | to_uuid }}"
|
|
state: present
|
|
register: result
|
|
|
|
- name: Assert result changed
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result.changed
|
|
|
|
- name: Create a 2nd User
|
|
awx.awx.user:
|
|
username: "{{ username }}2"
|
|
password: "{{ 65535 | random | to_uuid }}"
|
|
state: present
|
|
register: result
|
|
|
|
- name: Assert result changed
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result.changed
|
|
|
|
- name: Create teams
|
|
team:
|
|
name: "{{ item }}"
|
|
organization: Default
|
|
register: result
|
|
loop:
|
|
- "{{ team_name }}"
|
|
- "{{ team2_name }}"
|
|
|
|
- name: Assert result changed
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result.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
|
|
|
|
- name: Assert project_info is changed
|
|
ansible.builtin.assert:
|
|
that:
|
|
- project_info is changed
|
|
|
|
- name: Create job templates
|
|
job_template:
|
|
name: "{{ item }}"
|
|
project: "{{ project_name }}"
|
|
inventory: "Demo Inventory"
|
|
playbook: become.yml
|
|
with_items:
|
|
- jt1
|
|
- jt2
|
|
register: result
|
|
|
|
- name: Assert result changed
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result.changed
|
|
|
|
- name: Add Joe and teams to the update role of the default Project with lookup Organization
|
|
role:
|
|
user: "{{ username }}"
|
|
users:
|
|
- "{{ username }}2"
|
|
teams:
|
|
- "{{ team_name }}"
|
|
- "{{ team2_name }}"
|
|
role: update
|
|
lookup_organization: Default
|
|
project: "Demo Project"
|
|
state: "{{ item }}"
|
|
register: result
|
|
with_items:
|
|
- "present"
|
|
- "absent"
|
|
|
|
- name: Assert result changed
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result.changed
|
|
|
|
- name: Add Joe to the new project by ID
|
|
role:
|
|
user: "{{ username }}"
|
|
users:
|
|
- "{{ username }}2"
|
|
teams:
|
|
- "{{ team_name }}"
|
|
- "{{ team2_name }}"
|
|
role: update
|
|
project: "{{ project_info['id'] }}"
|
|
state: "{{ item }}"
|
|
register: result
|
|
with_items:
|
|
- "present"
|
|
- "absent"
|
|
|
|
- name: Assert result changed
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result.changed
|
|
|
|
- name: Add Joe as execution admin to Default Org.
|
|
role:
|
|
user: "{{ username }}"
|
|
users:
|
|
- "{{ username }}2"
|
|
role: execution_environment_admin
|
|
organizations: Default
|
|
state: "{{ item }}"
|
|
register: result
|
|
with_items:
|
|
- "present"
|
|
- "absent"
|
|
|
|
- name: Assert result changed
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result.changed
|
|
|
|
- name: Create a workflow
|
|
workflow_job_template:
|
|
name: test-role-workflow
|
|
organization: Default
|
|
state: present
|
|
|
|
- name: Add Joe to workflow execute role
|
|
role:
|
|
user: "{{ username }}"
|
|
users:
|
|
- "{{ username }}2"
|
|
role: execute
|
|
workflow: test-role-workflow
|
|
job_templates:
|
|
- jt1
|
|
- jt2
|
|
state: present
|
|
register: result
|
|
|
|
- name: Assert result changed
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result.changed
|
|
|
|
- name: Add Joe to nonexistent job template execute role
|
|
awx.awx.role:
|
|
user: "{{ username }}"
|
|
role: execute
|
|
job_template: "non existant temp"
|
|
state: present
|
|
register: results
|
|
ignore_errors: true
|
|
|
|
- name: Assert that adding a role to a non-existent template failed correctly
|
|
ansible.builtin.assert:
|
|
that:
|
|
- results.failed
|
|
- "'missing items' in results.msg"
|
|
|
|
- name: Add Joe to workflow execute role, no-op
|
|
role:
|
|
user: "{{ username }}"
|
|
users:
|
|
- "{{ username }}2"
|
|
role: execute
|
|
workflow: test-role-workflow
|
|
state: present
|
|
register: result
|
|
|
|
- name: Assert result did not change
|
|
ansible.builtin.assert:
|
|
that:
|
|
- "result is not changed"
|
|
|
|
- name: Add Joe to workflow approve role
|
|
role:
|
|
users:
|
|
- "{{ username }}2"
|
|
role: approval
|
|
workflow: test-role-workflow
|
|
state: present
|
|
register: result
|
|
|
|
- name: Assert result changed
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result.changed
|
|
|
|
- name: Create a 2nd organization
|
|
organization:
|
|
name: "{{ org2_name }}"
|
|
|
|
- name: Create a project in 2nd Organization
|
|
project:
|
|
name: "{{ project_name }}"
|
|
organization: "{{ org2_name }}"
|
|
scm_type: git
|
|
scm_url: https://github.com/ansible/test-playbooks
|
|
wait: true
|
|
register: project_info
|
|
|
|
- name: Add Joe and teams to the update role of the default Project with lookup from the 2nd Organization
|
|
role:
|
|
user: "{{ username }}"
|
|
users:
|
|
- "{{ username }}2"
|
|
teams:
|
|
- "{{ team_name }}"
|
|
- "{{ team2_name }}"
|
|
role: update
|
|
lookup_organization: "{{ org2_name }}"
|
|
project: "{{ project_name }}"
|
|
state: "{{ item }}"
|
|
register: result
|
|
with_items:
|
|
- "present"
|
|
- "absent"
|
|
|
|
- name: Assert result changed
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result.changed
|
|
|
|
always:
|
|
- name: Delete a User
|
|
ansible.builtin.user:
|
|
name: "{{ username }}"
|
|
state: absent
|
|
register: result
|
|
|
|
- name: Delete a 2nd User
|
|
ansible.builtin.user:
|
|
name: "{{ username }}2"
|
|
state: absent
|
|
register: result
|
|
|
|
- name: Delete teams
|
|
team:
|
|
name: "{{ item }}"
|
|
organization: Default
|
|
state: absent
|
|
register: result
|
|
loop:
|
|
- "{{ team_name }}"
|
|
- "{{ team2_name }}"
|
|
|
|
- name: Delete job templates
|
|
job_template:
|
|
name: "{{ item }}"
|
|
project: "{{ project_name }}"
|
|
inventory: "Demo Inventory"
|
|
playbook: debug.yml
|
|
state: absent
|
|
with_items:
|
|
- jt1
|
|
- jt2
|
|
|
|
- name: Delete the project
|
|
project:
|
|
name: "{{ project_name }}"
|
|
organization: Default
|
|
state: absent
|
|
register: del_res
|
|
until: del_res is succeeded
|
|
retries: 5
|
|
delay: 3
|
|
|
|
- name: Delete the 2nd organization
|
|
organization:
|
|
name: "{{ org2_name }}"
|
|
state: absent
|