From e50c8fc9c9b4c37a0af17b525bc910a39f195366 Mon Sep 17 00:00:00 2001 From: John Westcott IV Date: Thu, 21 May 2020 14:10:14 -0400 Subject: [PATCH] Updated docs and added block on tests --- awx_collection/plugins/modules/tower_token.py | 33 +++++++++-------- .../targets/tower_token/tasks/main.yml | 37 ++++++++++--------- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/awx_collection/plugins/modules/tower_token.py b/awx_collection/plugins/modules/tower_token.py index 7e229ac2c1..638b89cc6c 100644 --- a/awx_collection/plugins/modules/tower_token.py +++ b/awx_collection/plugins/modules/tower_token.py @@ -20,8 +20,9 @@ author: "John Westcott IV (@john-westcott-iv)" version_added: "2.3" short_description: create, update, or destroy Ansible Tower tokens. description: - - Create, update, or destroy Ansible Tower tokens. See + - Create or destroy Ansible Tower tokens. See U(https://www.ansible.com/tower) for an overview. + - If you create a token it is your responsibility to delete the token. options: description: description: @@ -60,22 +61,24 @@ extends_documentation_fragment: awx.awx.auth ''' EXAMPLES = ''' -- name: Create a new token using an existing token - tower_token: - description: '{{ token_description }}' - scope: "write" - state: present - tower_oauthtoken: "{{ ny_existing_token }}" - register: new_token +- block: + - name: Create a new token using an existing token + tower_token: + description: '{{ token_description }}' + scope: "write" + state: present + tower_oauthtoken: "{{ ny_existing_token }}" -- name: Use our new token to make another call - tower_job_list: - tower_oauthtoken: "{{ tower_token }}" + - name: Use our new token to make another call + tower_job_list: + tower_oauthtoken: "{{ tower_token }}" -- name: Delete our Token with the token we created - tower_token: - existing_token: "{{ tower_token }}" - state: absent + always: + - name: Delete our Token with the token we created + tower_token: + existing_token: "{{ tower_token }}" + state: absent + when: tower_token is defined ''' RETURNS = ''' diff --git a/awx_collection/tests/integration/targets/tower_token/tasks/main.yml b/awx_collection/tests/integration/targets/tower_token/tasks/main.yml index 74fcd05237..86edd620d7 100644 --- a/awx_collection/tests/integration/targets/tower_token/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_token/tasks/main.yml @@ -3,23 +3,26 @@ set_fact: token_description: "AWX-Collection-tests-tower_token-description-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" -- name: Create a Token - tower_token: - description: '{{ token_description }}' - scope: "write" - state: present - register: new_token +- block: + - name: Create a Token + tower_token: + description: '{{ token_description }}' + scope: "write" + state: present + register: new_token -- name: Validate our token works by token - tower_job_list: - tower_oauthtoken: "{{ tower_token.token }}" + - name: Validate our token works by token + tower_job_list: + tower_oauthtoken: "{{ tower_token.token }}" -- name: Validate out token works by object - tower_job_list: - tower_oauthtoken: "{{ tower_token }}" + - name: Validate out token works by object + tower_job_list: + tower_oauthtoken: "{{ tower_token }}" -- name: Delete our Token with our own token - tower_token: - existing_token: "{{ tower_token }}" - tower_oauthtoken: "{{ tower_token }}" - state: absent + always: + - name: Delete our Token with our own token + tower_token: + existing_token: "{{ tower_token }}" + tower_oauthtoken: "{{ tower_token }}" + state: absent + when: tower_token is defined