mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 01:17:37 -02:30
Update examples
This commit is contained in:
@@ -65,7 +65,6 @@ options:
|
|||||||
|
|
||||||
notes:
|
notes:
|
||||||
- If the query is not filtered properly this can cause a performance impact.
|
- If the query is not filtered properly this can cause a performance impact.
|
||||||
- In addition, the built in threshold is 10,000 items; if the query returns more an exception will be thrown.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
EXAMPLES = """
|
EXAMPLES = """
|
||||||
@@ -73,40 +72,34 @@ EXAMPLES = """
|
|||||||
set_fact:
|
set_fact:
|
||||||
tower_settings: "{{ lookup('awx.awx.tower_api', 'settings/ui') }}"
|
tower_settings: "{{ lookup('awx.awx.tower_api', 'settings/ui') }}"
|
||||||
|
|
||||||
- name: Lookup any users who are admins
|
- name: Report the usernames of all users with admin privs
|
||||||
set_fact:
|
debug:
|
||||||
admin_user_list_view: "{{ lookup('awx.awx.tower_api', 'users', query_params={ 'is_superuser': true }, return_objects=False) }}"
|
msg: "Admin users: {{ query('awx.awx.tower_api', 'users', query_params={ 'is_superuser': true }) | map(attribute='username') | join(', ') }}"
|
||||||
|
|
||||||
- name: Lookup any users who are admins and get their objects directly
|
- name: Lookup any users who are admins and get their objects directly
|
||||||
set_fact:
|
set_fact:
|
||||||
admin_user_object: "{{ lookup('awx.awx.tower_api', 'users', query_params={ 'is_superuser': true } ) }}"
|
admin_user_object: "{{ lookup('awx.awx.tower_api', 'users', query_params={ 'is_superuser': true } ) }}"
|
||||||
|
|
||||||
- name: Lookup the admin user and fail if there are more than one, and make sure its a list (without this, the response would be an object)
|
- name: Make sure user 'john' is an org admin of the default org if the user exists
|
||||||
set_fact:
|
tower_role:
|
||||||
actual_admin_user: "{{ lookup('awx.awx.tower_api', 'users', query_params={ 'username': 'admin' }, expect_one=True, wantlist=True) }}"
|
organization: Default
|
||||||
|
role: admin
|
||||||
|
user: john
|
||||||
|
state: absent
|
||||||
|
register: tower_role_revoke
|
||||||
|
when: "lookup('awx.awx.tower_api', 'users', query_params={ 'username': 'john' }) | length == 1"
|
||||||
|
|
||||||
- name: Get just the user ID of the admin user
|
- name: Create an inventory group with all 'foo' hosts
|
||||||
set_fact:
|
tower_group:
|
||||||
admin_user_id: "{{ lookup('awx.awx.tower_api', 'users', query_params={ 'username': 'admin' }, return_ids=True, expect_one=True) }}"
|
name: "Foo Group"
|
||||||
|
inventory: "Demo Inventory"
|
||||||
- name: Create a job template with a looked up credential from a folded lookup
|
hosts: >-
|
||||||
tower_job_template:
|
{{ query(
|
||||||
name: "{{ job_template_name }}"
|
'awx.awx.tower_api',
|
||||||
credentials: >-
|
'hosts',
|
||||||
{{ lookup(
|
query_params={ 'name__startswith' : 'foo', },
|
||||||
'awx.awx.tower_api',
|
) | map(attribute='name') | list }}
|
||||||
'credentials',
|
register: group_creation
|
||||||
query_params={ 'name' : credential_name },
|
|
||||||
return_ids=True,
|
|
||||||
expect_one=True,
|
|
||||||
wantlist=True
|
|
||||||
) }}
|
|
||||||
project: "{{ project_name }}"
|
|
||||||
inventory: Demo Inventory
|
|
||||||
playbook: hello_world.yml
|
|
||||||
job_type: run
|
|
||||||
state: present
|
|
||||||
register: create_jt
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RETURN = """
|
RETURN = """
|
||||||
|
|||||||
@@ -10,9 +10,10 @@
|
|||||||
- "AWX-Collection-tests-tower_api_lookup-user1-{{ test_id }}"
|
- "AWX-Collection-tests-tower_api_lookup-user1-{{ test_id }}"
|
||||||
- "AWX-Collection-tests-tower_api_lookup-user2-{{ test_id }}"
|
- "AWX-Collection-tests-tower_api_lookup-user2-{{ test_id }}"
|
||||||
- "AWX-Collection-tests-tower_api_lookup-user3-{{ test_id }}"
|
- "AWX-Collection-tests-tower_api_lookup-user3-{{ test_id }}"
|
||||||
credential_name: "AWX-Collection-tests-tower_api_lookup-cred1-{{ test_id }}"
|
hosts:
|
||||||
job_template_name: "AWX-Collection-tests-tower_api_lookup-jt1-{{ test_id }}"
|
- "AWX-Collection-tests-tower_api_lookup-host1-{{ test_id }}"
|
||||||
project_name: "AWX-Collection-tests-tower_api_lookup-proj1-{{ test_id }}"
|
- "AWX-Collection-tests-tower_api_lookup-host2-{{ test_id }}"
|
||||||
|
group_name: "AWX-Collection-tests-tower_api_lookup-group1-{{ test_id }}"
|
||||||
|
|
||||||
- name: Get our collection package
|
- name: Get our collection package
|
||||||
tower_meta:
|
tower_meta:
|
||||||
@@ -31,19 +32,11 @@
|
|||||||
register: user_creation_results
|
register: user_creation_results
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: Create our credential
|
- name: Create our hosts
|
||||||
tower_credential:
|
tower_host:
|
||||||
name: "{{ credential_name }}"
|
name: "{{ item }}"
|
||||||
organization: "Default"
|
inventory: "Demo Inventory"
|
||||||
credential_type: "Machine"
|
loop: "{{ hosts }}"
|
||||||
|
|
||||||
- name: Create a Demo Project
|
|
||||||
tower_project:
|
|
||||||
name: "{{ project_name }}"
|
|
||||||
organization: Default
|
|
||||||
state: present
|
|
||||||
scm_type: git
|
|
||||||
scm_url: https://github.com/ansible/ansible-tower-samples.git
|
|
||||||
|
|
||||||
- name: Test too many params (failure from validation of terms)
|
- name: Test too many params (failure from validation of terms)
|
||||||
set_fact:
|
set_fact:
|
||||||
@@ -79,7 +72,7 @@
|
|||||||
|
|
||||||
- name: Load user of a specific name with promoting objects
|
- name: Load user of a specific name with promoting objects
|
||||||
set_fact:
|
set_fact:
|
||||||
user_objects: "{{ lookup(plugin_name, 'users', query_params={ 'username' : user_creation_results['results'][0]['item'] }, return_objects=True, wantlist=True ) }}"
|
user_objects: "{{ query(plugin_name, 'users', query_params={ 'username' : user_creation_results['results'][0]['item'] }, return_objects=True ) }}"
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
@@ -90,7 +83,7 @@
|
|||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- item['id'] == user_creation_results['results'][0]['id']
|
- item['id'] == user_creation_results['results'][0]['id']
|
||||||
loop: "{{ lookup(plugin_name, 'users', query_params={ 'username' : user_creation_results['results'][0]['item'] }, wantlist=True) }}"
|
loop: "{{ query(plugin_name, 'users', query_params={ 'username' : user_creation_results['results'][0]['item'] } ) }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.id }}"
|
label: "{{ item.id }}"
|
||||||
|
|
||||||
@@ -126,7 +119,7 @@
|
|||||||
|
|
||||||
- name: Get the ID of the first user created and verify that it is correct
|
- name: Get the ID of the first user created and verify that it is correct
|
||||||
assert:
|
assert:
|
||||||
that: "{{ query(plugin_name, 'users', query_params={ 'username' : user_creation_results['results'][0]['item'] }, return_ids=True, wantlist=True)[0] }} == {{ user_creation_results['results'][0]['id'] }}"
|
that: "{{ query(plugin_name, 'users', query_params={ 'username' : user_creation_results['results'][0]['item'] }, return_ids=True)[0] }} == {{ user_creation_results['results'][0]['id'] }}"
|
||||||
|
|
||||||
- name: Try to get an ID of someone who does not exist
|
- name: Try to get an ID of someone who does not exist
|
||||||
set_fact:
|
set_fact:
|
||||||
@@ -185,13 +178,14 @@
|
|||||||
that:
|
that:
|
||||||
- "'CUSTOM_LOGO' in tower_settings"
|
- "'CUSTOM_LOGO' in tower_settings"
|
||||||
|
|
||||||
- name: Lookup any users who are admins
|
- name: Display the usernames of all admin users
|
||||||
set_fact:
|
debug:
|
||||||
admin_user_list_view: "{{ lookup('awx.awx.tower_api', 'users', query_params={ 'is_superuser': true }, return_objects=False) }}"
|
msg: "Admin users: {{ query('awx.awx.tower_api', 'users', query_params={ 'is_superuser': true }) | map(attribute='username') | join(', ') }}"
|
||||||
|
register: results
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "'count' in admin_user_list_view"
|
- "'admin' in results.msg"
|
||||||
|
|
||||||
- name: Lookup any users who are admins and get their objects directly
|
- name: Lookup any users who are admins and get their objects directly
|
||||||
set_fact:
|
set_fact:
|
||||||
@@ -201,62 +195,47 @@
|
|||||||
that:
|
that:
|
||||||
- "'count' not in admin_user_object"
|
- "'count' not in admin_user_object"
|
||||||
|
|
||||||
- name: Lookup the admin user and fail if there are more than one, and make sure its a list (without this, the response would be an object)
|
- name: Make sure user 'john' is an org admin of the default org if the user exists
|
||||||
set_fact:
|
tower_role:
|
||||||
actual_admin_user: "{{ lookup('awx.awx.tower_api', 'users', query_params={ 'username': 'admin' }, expect_one=True, wantlist=True) }}"
|
organization: Default
|
||||||
|
role: admin
|
||||||
|
user: "{{ usernames[0] }}"
|
||||||
|
state: absent
|
||||||
|
register: tower_role_revoke
|
||||||
|
when: "query('awx.awx.tower_api', 'users', query_params={ 'username': 'DNE_TESTING' }) | length == 1"
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- actual_admin_user | length() == 1
|
- tower_role_revoke is skipped
|
||||||
|
|
||||||
- name: Get just the user ID of the admin user
|
- name: Create an inventory group with all 'foo' hosts
|
||||||
set_fact:
|
tower_group:
|
||||||
admin_user_id: "{{ lookup('awx.awx.tower_api', 'users', query_params={ 'username': 'admin' }, return_ids=True, expect_one=True) }}"
|
name: "{{ group_name }}"
|
||||||
|
inventory: "Demo Inventory"
|
||||||
|
hosts: >-
|
||||||
|
{{ query(
|
||||||
|
'awx.awx.tower_api',
|
||||||
|
'hosts',
|
||||||
|
query_params={ 'name__endswith' : test_id, },
|
||||||
|
) | map(attribute='name') | list }}
|
||||||
|
register: group_creation
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that: group_creation is changed
|
||||||
- admin_user_id | int() >= 1
|
|
||||||
|
|
||||||
- name: Create a job template with a looked up credential from a folded lookup
|
|
||||||
tower_job_template:
|
|
||||||
name: "{{ job_template_name }}"
|
|
||||||
credentials: >-
|
|
||||||
{{ lookup(
|
|
||||||
'awx.awx.tower_api',
|
|
||||||
'credentials',
|
|
||||||
query_params={ 'name' : credential_name },
|
|
||||||
return_ids=True,
|
|
||||||
expect_one=True,
|
|
||||||
wantlist=True
|
|
||||||
) }}
|
|
||||||
project: "{{ project_name }}"
|
|
||||||
inventory: Demo Inventory
|
|
||||||
playbook: hello_world.yml
|
|
||||||
job_type: run
|
|
||||||
state: present
|
|
||||||
register: create_jt
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
- create_jt is changed
|
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Cleanup job template
|
- name: Cleanup group
|
||||||
tower_job_template:
|
tower_group:
|
||||||
name: "{{ job_template_name }}"
|
name: "{{ group_name }}"
|
||||||
|
inventory: "Demo Inventory"
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- name: Delete our credential
|
- name: Cleanup hosts
|
||||||
tower_credential:
|
tower_host:
|
||||||
name: "{{ credential_name }}"
|
name: "{{ item }}"
|
||||||
credential_type: Machine
|
inventory: "Demo Inventory"
|
||||||
state: absent
|
|
||||||
|
|
||||||
- name: Cleanup our project
|
|
||||||
tower_project:
|
|
||||||
name: "{{ project_name }}"
|
|
||||||
organization: Default
|
|
||||||
state: absent
|
state: absent
|
||||||
|
loop: "{{ hosts }}"
|
||||||
|
|
||||||
- name: Cleanup users
|
- name: Cleanup users
|
||||||
tower_user:
|
tower_user:
|
||||||
|
|||||||
Reference in New Issue
Block a user