add new name to multiple modules

This commit is contained in:
sean-m-ssullivan 2021-11-22 12:53:27 -05:00 committed by sean-m-sullivan
parent 03ed6e9755
commit bb8efbcc82
17 changed files with 172 additions and 34 deletions

View File

@ -26,6 +26,10 @@ options:
- Name of the application.
required: True
type: str
new_name:
description:
- Setting this option will change the existing name (looked up via the name field.
type: str
description:
description:
- Description of the application.
@ -96,6 +100,7 @@ def main():
# Any additional arguments that are not fields of the item can be added here
argument_spec = dict(
name=dict(required=True),
new_name=dict(),
description=dict(),
authorization_grant_type=dict(choices=["password", "authorization-code"]),
client_type=dict(choices=['public', 'confidential']),
@ -110,6 +115,7 @@ def main():
# Extract our parameters
name = module.params.get('name')
new_name = module.params.get("new_name")
description = module.params.get('description')
authorization_grant_type = module.params.get('authorization_grant_type')
client_type = module.params.get('client_type')
@ -129,7 +135,7 @@ def main():
# Create the data that gets sent for create and update
application_fields = {
'name': name,
'name': new_name if new_name else (module.get_item_name(application) if application else name),
'organization': org_id,
}
if authorization_grant_type is not None:

View File

@ -27,6 +27,10 @@ options:
- The name of the credential type.
required: True
type: str
new_name:
description:
- Setting this option will change the existing name (looked up via the name field.
type: str
description:
description:
- The description of the credential type to give more detail about it.
@ -89,6 +93,7 @@ def main():
# Any additional arguments that are not fields of the item can be added here
argument_spec = dict(
name=dict(required=True),
new_name=dict(),
description=dict(),
kind=dict(choices=list(KIND_CHOICES.keys())),
inputs=dict(type='dict'),
@ -101,7 +106,7 @@ def main():
# Extract our parameters
name = module.params.get('name')
new_name = None
new_name = module.params.get("new_name")
kind = module.params.get('kind')
state = module.params.get('state')

View File

@ -26,6 +26,10 @@ options:
- Name to use for the execution environment.
required: True
type: str
new_name:
description:
- Setting this option will change the existing name (looked up via the name field.
type: str
image:
description:
- The fully qualified url of the container image.
@ -74,6 +78,7 @@ def main():
# Any additional arguments that are not fields of the item can be added here
argument_spec = dict(
name=dict(required=True),
new_name=dict(),
image=dict(required=True),
description=dict(default=''),
organization=dict(),
@ -87,6 +92,7 @@ def main():
# Extract our parameters
name = module.params.get('name')
new_name = module.params.get("new_name")
image = module.params.get('image')
description = module.params.get('description')
state = module.params.get('state')
@ -98,7 +104,7 @@ def main():
module.delete_if_needed(existing_item)
new_fields = {
'name': name,
'name': new_name if new_name else (module.get_item_name(existing_item) if existing_item else name),
'image': image,
}
if description:

View File

@ -26,6 +26,10 @@ options:
- The name to use for the inventory.
required: True
type: str
new_name:
description:
- Setting this option will change the existing name (looked up via the name field.
type: str
copy_from:
description:
- Name or id to copy the inventory from.
@ -99,6 +103,7 @@ def main():
# Any additional arguments that are not fields of the item can be added here
argument_spec = dict(
name=dict(required=True),
new_name=dict(),
copy_from=dict(),
description=dict(),
organization=dict(required=True),
@ -114,6 +119,7 @@ def main():
# Extract our parameters
name = module.params.get('name')
new_name = module.params.get("new_name")
copy_from = module.params.get('copy_from')
description = module.params.get('description')
organization = module.params.get('organization')
@ -146,7 +152,7 @@ def main():
# Create the data that gets sent for create and update
inventory_fields = {
'name': module.get_item_name(inventory) if inventory else name,
'name': new_name if new_name else (module.get_item_name(inventory) if inventory else name),
'organization': org_id,
'kind': kind,
'host_filter': host_filter,

View File

@ -28,7 +28,7 @@ options:
type: str
new_name:
description:
- Setting this option will change the existing name (looed up via the name field.
- Setting this option will change the existing name (looked up via the name field.
type: str
copy_from:
description:

View File

@ -26,6 +26,10 @@ options:
- Name to use for the organization.
required: True
type: str
new_name:
description:
- Setting this option will change the existing name (looked up via the name field.
type: str
description:
description:
- The description to use for the organization.
@ -116,6 +120,7 @@ def main():
# Any additional arguments that are not fields of the item can be added here
argument_spec = dict(
name=dict(required=True),
new_name=dict(),
description=dict(),
default_environment=dict(),
custom_virtualenv=dict(),
@ -134,6 +139,7 @@ def main():
# Extract our parameters
name = module.params.get('name')
new_name = module.params.get("new_name")
description = module.params.get('description')
default_ee = module.params.get('default_environment')
custom_virtualenv = module.params.get('custom_virtualenv')
@ -186,7 +192,7 @@ def main():
association_fields['galaxy_credentials'].append(module.resolve_name_to_id('credentials', item))
# Create the data that gets sent for create and update
org_fields = {'name': module.get_item_name(organization) if organization else name}
org_fields = {'name': new_name if new_name else (module.get_item_name(organization) if organization else name),}
if description is not None:
org_fields['description'] = description
if default_ee is not None:

View File

@ -26,6 +26,10 @@ options:
- Name to use for the project.
required: True
type: str
new_name:
description:
- Setting this option will change the existing name (looked up via the name field.
type: str
copy_from:
description:
- Name or id to copy the project from.
@ -249,6 +253,7 @@ def main():
# Any additional arguments that are not fields of the item can be added here
argument_spec = dict(
name=dict(required=True),
new_name=dict(),
copy_from=dict(),
description=dict(),
scm_type=dict(choices=['manual', 'git', 'svn', 'insights'], default='manual'),
@ -281,6 +286,7 @@ def main():
# Extract our parameters
name = module.params.get('name')
new_name = module.params.get("new_name")
copy_from = module.params.get('copy_from')
scm_type = module.params.get('scm_type')
if scm_type == "manual":
@ -347,7 +353,7 @@ def main():
# Create the data that gets sent for create and update
project_fields = {
'name': module.get_item_name(project) if project else name,
'name': new_name if new_name else (module.get_item_name(project) if project else name),
'scm_type': scm_type,
'organization': org_id,
'scm_update_on_launch': scm_update_on_launch,

View File

@ -26,6 +26,10 @@ options:
- Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.
required: True
type: str
new_username:
description:
- Setting this option will change the existing username (looked up via the name field.
type: str
first_name:
description:
- First name of the user.
@ -114,6 +118,7 @@ def main():
# Any additional arguments that are not fields of the item can be added here
argument_spec = dict(
username=dict(required=True),
new_username=dict(),
first_name=dict(),
last_name=dict(),
email=dict(),
@ -129,6 +134,7 @@ def main():
# Extract our parameters
username = module.params.get('username')
new_username = module.params.get("new_username")
first_name = module.params.get('first_name')
last_name = module.params.get('last_name')
email = module.params.get('email')
@ -149,7 +155,7 @@ def main():
# Create the data that gets sent for create and update
new_fields = {}
if username is not None:
new_fields['username'] = module.get_item_name(existing_item) if existing_item else username
new_fields['username'] = new_username if new_username else (module.get_item_name(existing_item) if existing_item else username)
if first_name is not None:
new_fields['first_name'] = first_name
if last_name is not None:

View File

@ -810,7 +810,7 @@ def main():
)
# Get Workflow information in case one was just created.
existing_item = module.get_one('workflow_job_templates', name_or_id=name, **{'data': search_fields})
existing_item = module.get_one('workflow_job_templates', name_or_id=new_name if new_name else name, **{'data': search_fields})
workflow_job_template_id = existing_item['id']
# Destroy current nodes if selected.
if destroy_current_schema:

View File

@ -67,6 +67,8 @@ no_api_parameter_ok = {
'ad_hoc_command': ['interval', 'timeout', 'wait'],
# group parameters to perserve hosts and children.
'group': ['preserve_existing_children', 'preserve_existing_hosts'],
# user parameters to rename a user.
'user': ['new_username'],
# workflow_approval parameters that do not apply when approving an approval node.
'workflow_approval': ['action', 'interval', 'timeout', 'workflow_job_id'],
}

View File

@ -66,6 +66,18 @@
that:
- "result is changed"
- name: Rename an inventory
application:
name: "{{ app3_name }}"
new_name: "{{ app3_name }}a"
organization: Default
state: present
register: result
- assert:
that:
- result.changed
always:
- name: Delete our application
application:
@ -77,3 +89,4 @@
- "{{ app1_name }}"
- "{{ app2_name }}"
- "{{ app3_name }}"
- "{{ app3_name }}a"

View File

@ -3,25 +3,42 @@
set_fact:
cred_type_name: "AWX-Collection-tests-credential_type-cred-type-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Add Tower credential type
credential_type:
description: Credential type for Test
name: "{{ cred_type_name }}"
kind: cloud
inputs: {"fields": [{"type": "string", "id": "username", "label": "Username"}, {"secret": true, "type": "string", "id": "password", "label": "Password"}], "required": ["username", "password"]}
injectors: {"extra_vars": {"test": "foo"}}
register: result
- block:
- name: Add Tower credential type
credential_type:
description: Credential type for Test
name: "{{ cred_type_name }}"
kind: cloud
inputs: {"fields": [{"type": "string", "id": "username", "label": "Username"}, {"secret": true, "type": "string", "id": "password", "label": "Password"}], "required": ["username", "password"]}
injectors: {"extra_vars": {"test": "foo"}}
register: result
- assert:
that:
- "result is changed"
- assert:
that:
- "result is changed"
- name: Remove a Tower credential type
credential_type:
name: "{{ result.id }}"
state: absent
register: result
- name: Rename Tower credential type
credential_type:
name: "{{ cred_type_name }}"
new_name: "{{ cred_type_name }}a"
kind: cloud
- assert:
that:
- "result is changed"
register: result
- assert:
that:
- "result is changed"
always:
- name: Remove a Tower credential type
credential_type:
name: "{{ item }}"
state: absent
register: result
loop:
- "{{ cred_type_name }}"
- "{{ cred_type_name }}a"
- assert:
that:
- "result is changed"

View File

@ -34,14 +34,28 @@
that:
- "result is failed"
always:
- name: Delete the Test EE
- name: Rename the Test EEs
execution_environment:
name: "{{ ee_name }}"
state: absent
new_name: "{{ ee_name }}a"
image: quay.io/ansible/awx-ee
register: result
- assert:
that:
- "result is changed"
always:
- name: Delete the Test EEs
execution_environment:
name: "{{ item }}"
state: absent
image: quay.io/ansible/awx-ee
register: result
loop:
- "{{ ee_name }}"
- "{{ ee_name }}a"
- assert:
that:
- "result is changed"

View File

@ -74,9 +74,21 @@
that:
- result.copied
- name: Delete an Inventory
- name: Rename an inventory
inventory:
name: "copy_{{ inv_name1 }}"
new_name: "copy_{{ inv_name1 }}a"
organization: Default
state: present
register: result
- assert:
that:
- result.changed
- name: Delete an Inventory
inventory:
name: "copy_{{ inv_name1 }}a"
organization: Default
state: absent
register: result

View File

@ -70,9 +70,19 @@
name: "{{ group_name1 }}"
state: absent
- name: "Remove the organization"
- name: "Rename the organization"
organization:
name: "{{ org_name }}"
new_name: "{{ org_name }}a"
register: result
- assert:
that:
- "result is changed"
- name: "Remove the organization"
organization:
name: "{{ org_name }}a"
state: absent
register: result

View File

@ -183,6 +183,18 @@
that:
- job is successful
- name: Rename an inventory
project:
name: "{{ project_name3 }}"
new_name: "{{ project_name3 }}a"
organization: Default
state: present
register: result
- assert:
that:
- result.changed
always:
- name: Delete the test job_template
job_template:
@ -197,6 +209,12 @@
organization: Default
state: absent
- name: Delete the test project 3a
project:
name: "{{ project_name3 }}a"
organization: Default
state: absent
- name: Delete the test project 2
project:
name: "{{ project_name2 }}"

View File

@ -38,9 +38,20 @@
that:
- "result is not changed"
- name: Delete a User
- name: Rename a User
user:
username: "{{ username }}"
new_username: "{{ username }}-renamed"
email: joe@example.org
register: result
- assert:
that:
- "result is changed"
- name: Delete a User
user:
username: "{{ username }}-renamed"
email: joe@example.org
state: absent
register: result