Replace randstr with password plugin in collection tests

This commit is contained in:
Caleb Boylan 2020-01-19 19:15:14 -08:00
parent 4a6db13daa
commit fc80cf5241
6 changed files with 318 additions and 0 deletions

View File

@ -0,0 +1,57 @@
- name: create a tempdir for hostvars
local_action: shell mktemp -d
register: tempdir
- name: write a file w/ hostvars
local_action:
module: lineinfile
dest: "{{ tempdir.stdout }}/vars"
line: '{"foo": "bar"}'
create: true
- name: Generate an inventory name
set_fact:
inv_name: "inv-for-group-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Create an Inventory
tower_inventory:
name: "{{ inv_name }}"
organization: Default
state: present
- name: Create a Group
tower_group:
name: Some Group
inventory: "{{ inv_name }}"
state: present
source: ec2
variables: "@{{ tempdir.stdout }}/vars"
register: result
- assert:
that:
- "result is changed"
- name: Delete a Group
tower_group:
name: Some Group
inventory: "{{ inv_name }}"
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Check module fails with correct msg
tower_group:
name: test-group
description: Group Description
inventory: test-non-existing-inventory
state: present
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Failed to update the group, inventory not found: The requested object could not be found.'"

View File

@ -0,0 +1,56 @@
- name: create a tempdir for hostvars
local_action: shell mktemp -d
register: tempdir
- name: write a file w/ hostvars
local_action:
module: lineinfile
dest: "{{ tempdir.stdout }}/vars"
line: '{"foo": "bar"}'
create: true
- name: Generate an inventory name
set_fact:
inv_name: "inv-for-group-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Create an Inventory
tower_inventory:
name: "{{ inv_name }}"
organization: Default
state: present
- name: Create a Host
tower_host:
name: "some-host"
inventory: "{{ inv_name }}"
state: present
variables: "@{{ tempdir.stdout }}/vars"
register: result
- assert:
that:
- "result is changed"
- name: Delete a Host
tower_host:
name: "some-host"
inventory: "{{ inv_name }}"
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Check module fails with correct msg
tower_host:
name: test-host
description: Host Description
inventory: test-non-existing-inventory
state: present
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Failed to update host, inventory not found: The requested object could not be found.'"

View File

@ -0,0 +1,34 @@
---
- name: Add a Tower credential
tower_credential:
description: Credentials for Openstack Test project
name: openstack-test-credential
kind: openstack
organization: Default
project: Test
username: admin
host: https://example.org:5000
password: passw0rd
domain: test
- name: Add a Tower inventory
tower_inventory:
description: Test inventory
name: openstack-test-inventory
organization: Default
- name: Create a source inventory
tower_inventory_source:
name: "source-test-inventory {{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
description: Source for Test inventory
inventory: openstack-test-inventory
credential: openstack-test-credential
overwrite: True
update_on_launch: True
source_vars: "---\nprivate: false"
source: openstack
register: result
- assert:
that:
- "result is changed"

View File

@ -0,0 +1,44 @@
- name: Create an SCM Credential
tower_credential:
name: SCM Credential for JT
organization: Default
kind: scm
- name: Create a Demo Project
tower_project:
name: Job Template Test Project
organization: Default
state: present
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples.git
scm_credential: SCM Credential for JT
register: result
- name: Wait for the project to be status=successful
uri:
url: "{{ lookup('ENV', 'TOWER_HOST') }}/api/v2/projects/{{ result.id }}/"
method: GET
user: "{{ lookup('ENV', 'TOWER_USERNAME') }}"
password: "{{ lookup('ENV', 'TOWER_PASSWORD') }}"
validate_certs: false
force_basic_auth: true
return_content: true
register: result
until: result.json.summary_fields.last_update is defined and result.json.summary_fields.last_update.status == "successful"
retries: 60
delay: 1
- name: Create a Job Template
tower_job_template:
name: "hello-world {{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
project: Job Template Test Project
inventory: Demo Inventory
playbook: hello_world.yml
credential: Demo Credential
job_type: run
state: present
register: result
- assert:
that:
- "result is changed"

View File

@ -0,0 +1,95 @@
- name: Create an SCM Credential
tower_credential:
name: SCM Credential for Project
organization: Default
kind: scm
- name: Create a Project
tower_project:
name: my-project
organization: Default
state: present
scm_credential: SCM Credential for Project
register: result
- assert:
that:
- "result is changed"
- name: Delete a Project
tower_project:
name: my-project
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Create a git project without credentials
tower_project:
name: git project
organization: Default
scm_type: git
scm_url: https://github.com/ansible/ansible
- name: "Create {{ item }}"
tower_organization:
name: "{{ item }}"
loop:
- TestOrg1
- TestOrg2
- name: "Create credential"
tower_credential:
kind: scm
name: TestCred1
organization: "{{ item }}"
loop:
- TestOrg2
- TestOrg1
- name: Generate random project name appender
set_fact:
project_name_rand: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Create project TestProject
tower_project:
name: "TestProject {{ project_name_rand }}"
organization: TestOrg1
scm_type: git
scm_url: "https://github.com/ansible/ansible"
scm_credential: TestCred1
register: multi_org_cred_project
- assert:
that:
- "multi_org_cred_project is changed"
- name: Check module fails with correct msg
tower_project:
name: "TestProject {{ project_name_rand }}"
organization: Non Existing Org
scm_type: git
scm_url: "https://github.com/ansible/ansible"
scm_credential: TestCred1
register: result
ignore_errors: true
- assert:
that:
- "result.msg == 'Failed to update project, organization not found: Non Existing Org'"
- name: Check module fails with correct msg
tower_project:
name: "TestProject {{ project_name_rand }}"
organization: TestOrg1
scm_type: git
scm_url: "https://github.com/ansible/ansible"
scm_credential: Non Existing Credential
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Failed to update project, credential not found: Non Existing Credential'"

View File

@ -0,0 +1,32 @@
- name: Generate manual project dir name
set_fact:
project_name: "manual project {{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Generate manual project dir name
set_fact:
project_dir_name: "proj {{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: create a project directory for manual project
import_tasks: create_project_dir.yml
- name: Create a manual project
tower_project:
name: "{{ project_name }}"
organization: Default
scm_type: manual
local_path: "{{ project_dir_name }}"
register: result
- assert:
that:
- "result is changed"
- name: Delete a manual project
tower_project:
name: "{{ project_name }}"
state: absent
register: result
- assert:
that:
- "result is changed"