From 779ebc5a09c229bc5ccdd5deab00d729ee96751b Mon Sep 17 00:00:00 2001 From: Victor da Costa Date: Thu, 4 Apr 2019 22:43:33 +0200 Subject: [PATCH] tower-cli config and molecule --- .travis.yml | 20 +++--- meta/main.yml | 1 + molecule/default/molecule.yml | 62 ++++++++++++++++ .../test.yml => molecule/default/playbook.yml | 71 ++++++++++--------- molecule/default/requirements.yml | 2 + molecule/default/tests/test_default.py | 14 ++++ molecule/default/yaml-lint.yml | 6 ++ tasks/config.yml | 4 +- tasks/config/organization.yml | 1 + tasks/config/organization/credential.yml | 12 ++-- tasks/config/organization/credential_type.yml | 27 ++++--- tasks/config/organization/inventory.yml | 21 +++--- .../config/organization/inventory/source.yml | 13 ++-- tasks/config/organization/job_template.yml | 18 ++--- tasks/config/organization/main.yml | 24 +++---- tasks/config/organization/permission-cli.yml | 4 +- tasks/config/organization/permission.yml | 13 ++-- tasks/config/organization/project.yml | 18 ++--- tasks/config/organization/team.yml | 18 +++-- tasks/config/organization/team/member-cli.yml | 4 +- tasks/config/organization/user.yml | 38 +++++----- tasks/config/setting.yml | 2 + tasks/config/setting/license.yml | 5 +- tasks/config/tower_cli.yml | 22 ++++-- tasks/main.yml | 2 +- templates/tower_cli.cfg.j2 | 5 -- tests/custom_travis_wait.sh | 26 ------- tests/requirements.yml | 4 -- vars/main.yml | 3 +- 29 files changed, 287 insertions(+), 173 deletions(-) create mode 100644 molecule/default/molecule.yml rename tests/test.yml => molecule/default/playbook.yml (87%) create mode 100644 molecule/default/requirements.yml create mode 100644 molecule/default/tests/test_default.py create mode 100644 molecule/default/yaml-lint.yml delete mode 100644 templates/tower_cli.cfg.j2 delete mode 100755 tests/custom_travis_wait.sh delete mode 100644 tests/requirements.yml diff --git a/.travis.yml b/.travis.yml index 3e3af4a..808eecb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,20 +1,18 @@ --- +language: python services: docker env: - - distro: centos7 + matrix: + - MOLECULE_DISTRO: centos7 -script: - # Configure test script so we can run extra tests after playbook is run. - - export container_id=$(date +%s) - - export test_idempotence=false - - # Download test shim. - - wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/ - - chmod +x ${PWD}/tests/test.sh +install: + # Install test dependencies. + - pip install molecule docker - # Run tests (increasing the travis_wait timeout). - - tests/custom_travis_wait.sh ${PWD}/tests/test.sh +script: + # Run tests. + - molecule test notifications: webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/meta/main.yml b/meta/main.yml index c0b1d9b..8816adc 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,3 +1,4 @@ +--- dependencies: [] galaxy_info: diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..79c88ce --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,62 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint + options: + config-file: molecule/default/yaml-lint.yml +platforms: + - name: instance + image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true +provisioner: + log: false + name: ansible + lint: + name: ansible-lint + playbooks: + converge: ${MOLECULE_PLAYBOOK:-playbook.yml} +scenario: + name: default + create_sequence: + - create + - prepare + check_sequence: + - destroy + - dependency + - create + - prepare + - converge + - check + - destroy + converge_sequence: + - dependency + - create + - prepare + - converge + destroy_sequence: + - cleanup + - destroy + test_sequence: + - lint + - destroy + - dependency + - syntax + - create + - prepare + - converge + # - idempotence + - side_effect + - verify + - cleanup + - destroy +verifier: + name: testinfra + lint: + name: flake8 diff --git a/tests/test.yml b/molecule/default/playbook.yml similarity index 87% rename from tests/test.yml rename to molecule/default/playbook.yml index 93c15a2..e5dbe00 100644 --- a/tests/test.yml +++ b/molecule/default/playbook.yml @@ -1,25 +1,9 @@ --- -- hosts: all - gather_facts: yes +- name: Converge + hosts: all + become: false vars: - # Autorun victorock roles - autorun: true - - # Install pip package - pip_install_packages: - - name: ansible-tower-cli - - # Download tower_license.txt artifact - download: "gs" - download_user: "{{ lookup('ENV', 'GS_ACCESS_KEY_ID') }}" - download_pass: "{{ lookup('ENV', 'GS_SECRET_ACCESS_KEY') }}" - download_file: "tower_license.txt" - download_from: "/input/{{ download_file }}" - download_from_bucket: "darkbulb-image-store" - download_from_region: "europe-west1" - download_to: "/tmp/{{ download_file }}" - # Tower configuration tower_config: host: "localhost" @@ -27,11 +11,21 @@ password: "toweradmin" verify_ssl: false setting: - license: "{{ lookup('file', download_to) | from_json }}" + license: + company_name: "Red Hat" + contact_email: "vdacosta@redhat.com" + contact_name: "Victor da Costa" + hostname: "9d7cbfa4e6a548578e32250039b40026" + instance_count: 10 + license_date: 2122451371 + license_key: "0219bcbd294c57dfebdc638ffdc1eeb8bbdbd1000728b0d85554d4cd79f37863" + license_type: "basic" + subscription_name: "Red Hat Ansible Tower, Self-Support (10 Managed Nodes)" + eula_accepted: true organization: README: - name: "README" - description: "README" + name: "Default" + description: "Default" users: - name: "infraops" password: "infraops" @@ -123,28 +117,24 @@ description: "Dev: netops:ansible-tower-example" scm_credential: "empty-scm" scm_type: "git" - scm_branch: "dev" scm_update_on_launch: true scm_url: "https://github.com/ansible/tower-example" - name: "Dev: devops:ansible-tower-example" description: "Dev: devops:ansible-tower-example" scm_credential: "empty-scm" scm_type: "git" - scm_branch: "dev" scm_update_on_launch: true scm_url: "https://github.com/ansible/tower-example" - name: "Dev: sysops:ansible-tower-example" description: "Dev: sysops:ansible-tower-example" scm_credential: "empty-scm" scm_type: "git" - scm_branch: "dev" scm_update_on_launch: true scm_url: "https://github.com/ansible/tower-example" - name: "Dev: secops:ansible-tower-example" description: "Dev: secops:ansible-tower-example" scm_credential: "empty-scm" scm_type: "git" - scm_branch: "dev" scm_update_on_launch: true scm_url: "https://github.com/ansible/tower-example" inventories: @@ -152,6 +142,8 @@ description: "infraops" - name: "netops" description: "netops" + - name: "devops" + description: "devops" - name: "sysops" description: "sysops" - name: "secops" @@ -168,7 +160,7 @@ network_credential: "network-nxos-net" - name: "Dev: devops:helloworld" description: "Dev: devops:helloworld" - project: "Dev: netops:ansible-tower-example" + project: "Dev: devops:ansible-tower-example" playbook: "helloworld.yml" inventory: "devops" forks: 50 @@ -257,6 +249,18 @@ - team: "sysops" role: "admin" project: "Dev: sysops:ansible-tower-example" + - team: "netops" + role: "admin" + inventory: "netops" + - team: "devops" + role: "admin" + inventory: "devops" + - team: "secops" + role: "admin" + inventory: "secops" + - team: "sysops" + role: "admin" + inventory: "sysops" - team: "netops" role: "admin" job_template: "Dev: netops:helloworld" @@ -270,9 +274,12 @@ role: "admin" job_template: "Dev: secops:helloworld" + pre_tasks: + - name: Install dependencies (RedHat). + yum: + name: "epel-release" + state: "present" + roles: - - role: victorock.tower_setup - when: ansible_os_family == "RedHat" - - role: geerlingguy.pip - - role: victorock.download - - role: role_under_test + - victorock.tower_setup + - ansible-role-tower-config diff --git a/molecule/default/requirements.yml b/molecule/default/requirements.yml new file mode 100644 index 0000000..69bbeeb --- /dev/null +++ b/molecule/default/requirements.yml @@ -0,0 +1,2 @@ +--- +- name: victorock.tower_setup diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py new file mode 100644 index 0000000..eedd64a --- /dev/null +++ b/molecule/default/tests/test_default.py @@ -0,0 +1,14 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_hosts_file(host): + f = host.file('/etc/hosts') + + assert f.exists + assert f.user == 'root' + assert f.group == 'root' diff --git a/molecule/default/yaml-lint.yml b/molecule/default/yaml-lint.yml new file mode 100644 index 0000000..a3dbc38 --- /dev/null +++ b/molecule/default/yaml-lint.yml @@ -0,0 +1,6 @@ +--- +extends: default +rules: + line-length: + max: 120 + level: warning diff --git a/tasks/config.yml b/tasks/config.yml index 864fac2..7c51544 100644 --- a/tasks/config.yml +++ b/tasks/config.yml @@ -4,8 +4,8 @@ - name: "Configure Setting" import_tasks: "config/setting.yml" - when: tower_config.setting is mapping + when: tower_config.setting is defined - name: "Configure Organization" import_tasks: "config/organization.yml" - when: tower_config.organization is mapping + when: tower_config.organization is defined diff --git a/tasks/config/organization.yml b/tasks/config/organization.yml index 3f321b1..98f40b2 100644 --- a/tasks/config/organization.yml +++ b/tasks/config/organization.yml @@ -1,3 +1,4 @@ +--- - name: "config.organization: Process [ organization ]" when: tower_config_organization is defined include_tasks: "organization/main.yml" diff --git a/tasks/config/organization/credential.yml b/tasks/config/organization/credential.yml index 1ee6b4d..6b6418a 100644 --- a/tasks/config/organization/credential.yml +++ b/tasks/config/organization/credential.yml @@ -1,10 +1,10 @@ --- -- name: "config.organization.credential: Ensure state of credential: [ {{ tower_config_organization_credential.name }} ]" +- name: "config.organization.credential: [ {{ tower_config_organization_credential.name }} ]" tower_credential: - tower_host: "{{ tower_config.host }}" - tower_username: "{{ tower_config.username }}" - tower_password: "{{ tower_config.password }}" - tower_verify_ssl: "{{ tower_config.verify_ssl|bool }}" + tower_host: "{{ tower_config.host | default(omit) }}" + tower_username: "{{ tower_config.username | default(omit) }}" + tower_password: "{{ tower_config.password | default(omit) }}" + tower_verify_ssl: "{{ tower_config.verify_ssl | default(omit) }}" name: "{{ tower_config_organization_credential.name }}" username: "{{ tower_config_organization_credential.username | default(omit) }}" password: "{{ tower_config_organization_credential.password | default(omit) }}" @@ -27,3 +27,5 @@ subscription: "{{ tower_config_organization_credential.subscription | default(omit) }}" client: "{{ tower_config_organization_credential.client | default(omit) }}" state: "{{ tower_config_organization_credential.state | default(omit) }}" + async: 15 + poll: 1 diff --git a/tasks/config/organization/credential_type.yml b/tasks/config/organization/credential_type.yml index 597e0ab..b12054e 100644 --- a/tasks/config/organization/credential_type.yml +++ b/tasks/config/organization/credential_type.yml @@ -1,10 +1,11 @@ -- name: "config.organization.credential_type: Ensure state of credential_type: [ {{ tower_config_organization_credential_type.name }} ]" +--- +- name: "config.organization.credential_type: [ {{ tower_config_organization_credential_type.name }} ]" vars: url_host: "https://{{ tower_config.host }}" url_api: "/api/v2/credential_types/" user: "{{ tower_config.username }}" password: "{{ tower_config.password }}" - validate_certs: "{{ tower_config.verify_ssl|bool }}" + validate_certs: "{{ tower_config.verify_ssl | default(omit) }}" force_basic_auth: true headers: Content-Type: "application/json" @@ -13,16 +14,21 @@ name: "{{ tower_config_organization_credential_type.name | mandatory }}" description: "{{ tower_config_organization_credential_type.name | default('') }}" kind: "{{ tower_config_organization_credential_type.kind | default('cloud') }}" - inputs: {{ tower_config_organization_credential_type.inputs | mandatory }} - injectors: {{ tower_config_organization_credential_type.injectors | mandatory }} + inputs: "{{ tower_config_organization_credential_type.inputs | mandatory }}" + injectors: "{{ tower_config_organization_credential_type.injectors | mandatory }}" body_format: "{{ tower_config.format }}" block: - when: "tower_config_organization_credential_type.state|default('present') == 'present'" block: - - uri: + - vars: + a: "{{ url_host }}" + b: "{{ url_api }}" + c: "{{ tower_config_organization_credential_type.name }}" + d: "{{ tower_config_organization_credential_type.kind | default('cloud') }}" + uri: method: GET - url: "{{ url_host }}{{ url_api }}{{ tower_config_organization_credential_type.name }}+{{ tower_config_organization_credential_type.kind | default('cloud') }}" + url: "{{ a }}{{ b }}{{ c }}+{{ d }}" user: "{{ user }}" password: "{{ password }}" validate_certs: "{{ validate_certs }}" @@ -57,9 +63,14 @@ register: reg_credential_type - when: "tower_config_organization_credential_type.state|default('present') == 'absent'" block: - - uri: + - vars: + a: "{{ url_host }}" + b: "{{ url_api }}" + c: "{{ tower_config_organization_credential_type.name }}" + d: "{{ tower_config_organization_credential_type.kind | default('cloud') }}" + uri: method: GET - url: "{{ url_host }}{{ url_api }}{{ tower_config_organization_credential_type.name }}+{{ tower_config_organization_credential_type.kind | default('cloud') }}" + url: "{{ a }}{{ b }}{{ c }}+{{ d }}" user: "{{ user }}" password: "{{ password }}" validate_certs: "{{ validate_certs }}" diff --git a/tasks/config/organization/inventory.yml b/tasks/config/organization/inventory.yml index a23bd83..a930e5f 100644 --- a/tasks/config/organization/inventory.yml +++ b/tasks/config/organization/inventory.yml @@ -1,18 +1,23 @@ -- name: "organization.inventory: Ensure state of inventory: [ {{ tower_config_organization_inventory.name }} ]" +--- +- name: "config.organization.inventory: [ {{ tower_config_organization_inventory.name }} ]" tower_inventory: - tower_host: "{{ tower_config.host }}" - tower_username: "{{ tower_config.username }}" - tower_password: "{{ tower_config.password }}" - tower_verify_ssl: "{{ tower_config.verify_ssl|bool }}" + tower_host: "{{ tower_config.host | default(omit) }}" + tower_username: "{{ tower_config.username | default(omit) }}" + tower_password: "{{ tower_config.password | default(omit) }}" + tower_verify_ssl: "{{ tower_config.verify_ssl | default(omit) }}" name: "{{ tower_config_organization_inventory.name }}" - organization: "{{ tower_config_organization.name }}" + organization: "{{ tower_config_organization.name }}" description: "{{ tower_config_organization_inventory.description | default(omit) }}" state: "{{ tower_config_organization_inventory.state | default(omit) }}" + async: 15 + poll: 1 - name: "organizations.inventory: Process [ sources ]" when: tower_config_organization_inventory.sources is sequence include_tasks: "inventory/source.yml" loop: "{{ tower_config_organization_inventory.sources }}" loop_control: - loop_var: tower_config_organization_inventory_source - label: "{{ tower_config_organization_inventory_source.name }}" + loop_var: tower_config_organization_inventory_source + label: "{{ tower_config_organization_inventory_source.name }}" + async: 15 + poll: 1 diff --git a/tasks/config/organization/inventory/source.yml b/tasks/config/organization/inventory/source.yml index de2a6ec..ef7010e 100644 --- a/tasks/config/organization/inventory/source.yml +++ b/tasks/config/organization/inventory/source.yml @@ -1,9 +1,10 @@ -- name: "organization.inventory: Ensure state of inventory source: [ {{ tower_config_organization_inventory_source.name }} ]" +--- +- name: "config.organization.inventory.source: [ {{ tower_config_organization_inventory_source.name }} ]" tower_inventory_source: - tower_host: "{{ tower_config.host }}" - tower_username: "{{ tower_config.username }}" - tower_password: "{{ tower_config.username }}" - tower_verify_ssl: "{{ tower_config.verify_ssl|bool }}" + tower_host: "{{ tower_config.host | default(omit) }}" + tower_username: "{{ tower_config.username | default(omit) }}" + tower_password: "{{ tower_config.password | default(omit) }}" + tower_verify_ssl: "{{ tower_config.verify_ssl | default(omit) }}" name: "{{ tower_config_organization_inventory_source.name }}" description: "{{ tower_config_organization_inventory_source.description | default(omit) }}" state: "{{ tower_config_organization_inventory_source.state | default(omit) }}" @@ -19,3 +20,5 @@ source_regions: "{{ tower_config_organization_inventory_source.source_regions | default(omit) }}" source_script: "{{ tower_config_organization_inventory_source.source_script | default(omit) }}" source_vars: "{{ tower_config_organization_inventory_source.source_vars | default(omit) }}" + async: 15 + poll: 1 diff --git a/tasks/config/organization/job_template.yml b/tasks/config/organization/job_template.yml index 5771bc8..d822ec4 100644 --- a/tasks/config/organization/job_template.yml +++ b/tasks/config/organization/job_template.yml @@ -1,20 +1,20 @@ --- -- name: "config.organization: Ensure state of job_template: [ {{ tower_config_organization_job_template.name }} ]" +- name: "config.organization.job_template: [ {{ tower_config_organization_job_template.name }} ]" tower_job_template: - tower_host: "{{ tower_config.host }}" - tower_username: "{{ tower_config.username }}" - tower_password: "{{ tower_config.password }}" - tower_verify_ssl: "{{ tower_config.verify_ssl|bool }}" + tower_host: "{{ tower_config.host | default(omit) }}" + tower_username: "{{ tower_config.username | default(omit) }}" + tower_password: "{{ tower_config.password | default(omit) }}" + tower_verify_ssl: "{{ tower_config.verify_ssl | default(omit) }}" name: "{{ tower_config_organization_job_template.name }}" playbook: "{{ tower_config_organization_job_template.playbook }}" - project: "{{ tower_config_organization_job_template.project }}" + project: "{{ tower_config_organization_job_template.project }}" description: "{{ tower_config_organization_job_template.description | default(omit) }}" job_type: "{{ tower_config_organization_job_template.job_type | default('run') }}" ask_job_type: "{{ tower_config_organization_job_template.ask_job_type | default(omit) }}" credential: "{{ tower_config_organization_job_template.credential | default(omit) }}" vault_credential: "{{ tower_config_organization_job_template.vault_credential | default(omit) }}" ask_credential: "{{ tower_config_organization_job_template.ask_credential | default(omit) }}" - inventory: "{{ tower_config_organization_job_template.inventory }}" + inventory: "{{ tower_config_organization_job_template.inventory }}" ask_inventory: "{{ tower_config_organization_job_template.ask_inventory | default(omit) }}" extra_vars_path: "{{ tower_config_organization_job_template.extra_vars_path | default(omit) }}" ask_extra_vars: "{{ tower_config_organization_job_template.ask_extra_vars | default(omit) }}" @@ -25,6 +25,8 @@ forks: "{{ tower_config_organization_job_template.forks | default(omit) }}" host_config_key: "{{ tower_config_organization_job_template.host_config_key | default(omit) }}" limit: "{{ tower_config_organization_job_template.limit | default(omit) }}" -# ask_limit_on_launch: "{{ tower_config_organization_job_template.ask_limit_on_launch | default(omit) }}" + # ask_limit_on_launch: "{{ tower_config_organization_job_template.ask_limit_on_launch | default(omit) }}" verbosity: "{{ tower_config_organization_job_template.verbosity | default(omit) }}" state: "{{ tower_config_organization_job_template.state | default(omit) }}" + async: 15 + poll: 1 diff --git a/tasks/config/organization/main.yml b/tasks/config/organization/main.yml index 19d2eda..090af78 100644 --- a/tasks/config/organization/main.yml +++ b/tasks/config/organization/main.yml @@ -1,10 +1,10 @@ --- -- name: "config.organization: Ensure state of organization: [ {{ tower_config_organization.name }} ]" +- name: "config.organization: [ {{ tower_config_organization.name }} ]" tower_organization: - tower_host: "{{ tower_config.host }}" - tower_username: "{{ tower_config.username }}" - tower_password: "{{ tower_config.password }}" - tower_verify_ssl: "{{ tower_config.verify_ssl|bool }}" + tower_host: "{{ tower_config.host | default(omit) }}" + tower_username: "{{ tower_config.username | default(omit) }}" + tower_password: "{{ tower_config.password | default(omit) }}" + tower_verify_ssl: "{{ tower_config.verify_ssl | default(omit) }}" name: "{{ tower_config_organization.name }}" description: "{{ tower_config_organization.description | default(omit) }}" state: "{{ tower_config_organization.state | default('present') }}" @@ -58,13 +58,13 @@ label: "{{ tower_config_organization_job_template.name }}" ### Buggy module -#- name: "config.organization: Process [ permissions ]" -# when: tower_config_organization.permissions is sequence -# include_tasks: "permission.yml" -# loop: "{{ tower_config_organization.permissions }}" -# loop_control: -# loop_var: tower_config_organization_permission -# label: "{{ tower_config_organization_permission.team }}" +# - name: "config.organization: Process [ permissions ]" +# when: tower_config_organization.permissions is sequence +# include_tasks: "permission.yml" +# loop: "{{ tower_config_organization.permissions }}" +# loop_control: +# loop_var: tower_config_organization_permission +# label: "{{ tower_config_organization_permission.team }}" - name: "config.organization: Process [ permissions ] with tower-cli" when: tower_config_organization.permissions is defined diff --git a/tasks/config/organization/permission-cli.yml b/tasks/config/organization/permission-cli.yml index 15a7cc7..280f5cb 100644 --- a/tasks/config/organization/permission-cli.yml +++ b/tasks/config/organization/permission-cli.yml @@ -1,3 +1,5 @@ -- name: "config.organization.permission-cli: Ensure permissions for role [ {{ tower_config_organization_permission.role }} ]" +--- +- name: "config.organization.permission-cli: [ {{ tower_config_organization_permission.role }} ]" command: "{{ lookup('template', 'permission-cli.j2') }}" register: tower_cli_permission + when: tower_config_organization_permission.role is defined diff --git a/tasks/config/organization/permission.yml b/tasks/config/organization/permission.yml index ca73b73..0659350 100644 --- a/tasks/config/organization/permission.yml +++ b/tasks/config/organization/permission.yml @@ -1,9 +1,10 @@ -- name: "config.organization.permission: Ensure permissions for role [ {{ tower_config_organization_permission.role }} ]" +--- +- name: "config.organization.permission: [ {{ tower_config_organization_permission.role }} ]" tower_role: - tower_host: "{{ tower_config.host }}" - tower_username: "{{ tower_config.username }}" - tower_password: "{{ tower_config.password }}" - tower_verify_ssl: "{{ tower_config.verify_ssl|bool }}" + tower_host: "{{ tower_config.host | default(omit) }}" + tower_username: "{{ tower_config.username | default(omit) }}" + tower_password: "{{ tower_config.password | default(omit) }}" + tower_verify_ssl: "{{ tower_config.verify_ssl | default(omit) }}" role: "{{ tower_config_organization_permission.role }}" team: "{{ tower_config_organization_permission.team | default(omit) }}" user: "{{ tower_config_organization_permission.user | default(omit) }}" @@ -14,3 +15,5 @@ project: "{{ tower_config_organization_permission.project | default(omit) }}" target_team: "{{ tower_config_organization_permission.target_team | default(omit) }}" state: "{{ tower_config_organization_permission.state | default(omit) }}" + async: 15 + poll: 1 diff --git a/tasks/config/organization/project.yml b/tasks/config/organization/project.yml index f29387e..7d38b6a 100644 --- a/tasks/config/organization/project.yml +++ b/tasks/config/organization/project.yml @@ -1,20 +1,22 @@ --- -- name: "config.organization.project: Ensure state of project: [ {{ tower_config_organization_project.name }} ]" +- name: "config.organization.project: [ {{ tower_config_organization_project.name }} ]" tower_project: - tower_host: "{{ tower_config.host }}" - tower_username: "{{ tower_config.username }}" - tower_password: "{{ tower_config.password }}" - tower_verify_ssl: "{{ tower_config.verify_ssl|bool }}" + tower_host: "{{ tower_config.host | default(omit) }}" + tower_username: "{{ tower_config.username | default(omit) }}" + tower_password: "{{ tower_config.password | default(omit) }}" + tower_verify_ssl: "{{ tower_config.verify_ssl | default(omit) }}" name: "{{ tower_config_organization_project.name }}" organization: "{{ tower_config_organization.name | default(omit) }}" description: "{{ tower_config_organization_project.description | default(omit) }}" -# https://github.com/ansible/ansible/issues/32274 -# scm_credential: "{{ tower_config_organization_project.scm_credential | default(omit) }}" + # https://github.com/ansible/ansible/issues/32274 + # scm_credential: "{{ tower_config_organization_project.scm_credential | default(omit) }}" scm_credential: "{{ tower_config_organization_project.scm_credential }}" scm_type: "{{ tower_config_organization_project.scm_type | default(omit) }}" scm_branch: "{{ tower_config_organization_project.scm_branch | default(omit) }}" scm_update_on_launch: "{{ tower_config_organization_project.scm_update_on_launch | default(omit) }}" scm_delete_on_update: "{{ tower_config_organization_project.scm_delete_on_update | default(omit) }}" - scm_clean: "{{ tower_config_organization_project.scm_clean | default(omit) }}" + scm_clean: "{{ tower_config_organization_project.scm_clean | default(omit) }}" scm_url: "{{ tower_config_organization_project.scm_url | default(omit) }}" state: "{{ tower_config_organization_project.state | default(omit) }}" + async: 15 + poll: 1 diff --git a/tasks/config/organization/team.yml b/tasks/config/organization/team.yml index 3e475ad..eab38f8 100644 --- a/tasks/config/organization/team.yml +++ b/tasks/config/organization/team.yml @@ -1,20 +1,24 @@ --- -- name: "config.organization.team: Ensure state of team: [ {{ tower_config_organization_team.name }} ]" +- name: "config.organization.team: [ {{ tower_config_organization_team.name }} ]" tower_team: - tower_host: "{{ tower_config.host }}" - tower_username: "{{ tower_config.username }}" - tower_password: "{{ tower_config.password }}" - tower_verify_ssl: "{{ tower_config.verify_ssl|bool }}" + tower_host: "{{ tower_config.host | default(omit) }}" + tower_username: "{{ tower_config.username | default(omit) }}" + tower_password: "{{ tower_config.password | default(omit) }}" + tower_verify_ssl: "{{ tower_config.verify_ssl | default(omit) }}" name: "{{ tower_config_organization_team.name }}" organization: "{{ tower_config_organization.name }}" description: "{{ tower_config_organization_team.description | default(omit) }}" state: "{{ tower_config_organization_team.state | default(omit) }}" - + async: 15 + poll: 1 + ## Functionality not available in the module today -- name: "config.organization.team: Ensure membership of team: [ {{ tower_config_organization_team.name }} ] with tower-cli" +- name: "config.organization.team.member-cli: [ {{ tower_config_organization_team.name }} ]" when: tower_config_organization_team.members is defined include_tasks: "team/member-cli.yml" loop: "{{ tower_config_organization_team.members }}" loop_control: loop_var: tower_config_organization_team_member label: "{{ tower_config_organization_team_member.name }}" + async: 15 + poll: 1 diff --git a/tasks/config/organization/team/member-cli.yml b/tasks/config/organization/team/member-cli.yml index 90cdd3a..0ef20a6 100644 --- a/tasks/config/organization/team/member-cli.yml +++ b/tasks/config/organization/team/member-cli.yml @@ -1,3 +1,5 @@ -- name: "config.team.member-cli: Ensure membership for [ {{ tower_config_organization_team.name }}:{{ tower_config_organization_team_member.name }} ]" +--- +- name: "config.organization.team.member-cli: [ {{ tower_config_organization_team.name }} ]" command: "{{ lookup('template', 'member-cli.j2') }}" register: tower_cli_team + when: tower_config_organization_team.name is defined diff --git a/tasks/config/organization/user.yml b/tasks/config/organization/user.yml index d5a714b..2f4eccd 100644 --- a/tasks/config/organization/user.yml +++ b/tasks/config/organization/user.yml @@ -1,26 +1,30 @@ --- -- name: "config.organization.user: Ensure state of user: [ {{ tower_config_organization_user.name }} ]" +- name: "config.organization.user: [ {{ tower_config_organization_user.name }} ]" tower_user: - tower_host: "{{ tower_config.host }}" - tower_username: "{{ tower_config.username }}" - tower_password: "{{ tower_config.password }}" - tower_verify_ssl: "{{ tower_config.verify_ssl|bool }}" - username: "{{ tower_config_organization_user.name }}" - password: "{{ tower_config_organization_user.password }}" - email: "{{ tower_config_organization_user.email }}" - first_name: "{{ tower_config_organization_user.first_name }}" - last_name: "{{ tower_config_organization_user.last_name }}" - superuser: "{{ tower_config_organization_user.superuser|bool | default(omit) }}" - auditor: "{{ tower_config_organization_user.auditor|bool | default(omit) }}" - state: "{{ tower_config_organization_user.state | default(omit) }}" + tower_host: "{{ tower_config.host | default(omit) }}" + tower_username: "{{ tower_config.username | default(omit) }}" + tower_password: "{{ tower_config.password | default(omit) }}" + tower_verify_ssl: "{{ tower_config.verify_ssl | default(omit) }}" + username: "{{ tower_config_organization_user.name }}" + password: "{{ tower_config_organization_user.password | default(omit) }}" + email: "{{ tower_config_organization_user.email }}" + first_name: "{{ tower_config_organization_user.first_name | default(omit) }}" + last_name: "{{ tower_config_organization_user.last_name | default(omit) }}" + superuser: "{{ tower_config_organization_user.superuser | bool or omit }}" + auditor: "{{ tower_config_organization_user.auditor | bool or omit }}" + state: "{{ tower_config_organization_user.state | default(omit) }}" + async: 15 + poll: 1 -- name: "config.organization.permission: Ensure membership in Organization for user: [ {{ tower_config_organization_user.name }} ]" +- name: "config.organization.permission: [ {{ tower_config_organization_user.name }} ]" tower_role: tower_host: "{{ tower_config.host }}" tower_username: "{{ tower_config.username }}" tower_password: "{{ tower_config.password }}" tower_verify_ssl: "{{ tower_config.verify_ssl|bool }}" - user: "{{ tower_config_organization_user.name }}" + user: "{{ tower_config_organization_user.name }}" organization: "{{ tower_config_organization.name }}" - role: "member" - state: "present" + role: "member" + state: "present" + async: 15 + poll: 1 diff --git a/tasks/config/setting.yml b/tasks/config/setting.yml index f2e2006..c18a3e4 100644 --- a/tasks/config/setting.yml +++ b/tasks/config/setting.yml @@ -1,2 +1,4 @@ +--- - name: "config.setting-cli: Process [ license ]" include_tasks: "setting/license.yml" + when: tower_config.setting.license is defined diff --git a/tasks/config/setting/license.yml b/tasks/config/setting/license.yml index 8c46919..7ed4039 100644 --- a/tasks/config/setting/license.yml +++ b/tasks/config/setting/license.yml @@ -1,9 +1,10 @@ -- name: "config.setting.license: Ensure state of LICENSE" +--- +- name: "config.setting.license: Ensure state" uri: url: "https://{{ tower_config.host }}/api/v1/config/" user: "{{ tower_config.username }}" password: "{{ tower_config.password }}" - validate_certs: "{{ tower_config.verify_ssl|bool }}" + validate_certs: "{{ tower_config.verify_ssl | default(omit) }}" force_basic_auth: true headers: Content-Type: "application/json" diff --git a/tasks/config/tower_cli.yml b/tasks/config/tower_cli.yml index 7c38e85..a22dec9 100644 --- a/tasks/config/tower_cli.yml +++ b/tasks/config/tower_cli.yml @@ -1,5 +1,19 @@ -- name: "config.tower_cli: Generate tower_cli.cfg" - template: - src: "tower_cli.cfg.j2" - dest: "~/.tower_cli.cfg" +--- +- name: "config.tower_cli: Configure" + when: tower_config[tower_config_ini_key] is defined + ini_file: + path: "~/.tower_cli.cfg" + section: "general" + option: "{{ tower_config_ini_key }}" + value: "{{ tower_config[tower_config_ini_key] }}" mode: 0600 + loop: + - host + - username + - password + - verify_ssl + - format + - oauth_token + loop_control: + loop_var: tower_config_ini_key + label: "{{ tower_config_ini_key }}" diff --git a/tasks/main.yml b/tasks/main.yml index 7d878bc..847f3cf 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -4,4 +4,4 @@ tower_config: "{{ _tower_config | combine(tower_config) }}" - name: "config.yml" - import_tasks: config.yml \ No newline at end of file + import_tasks: config.yml diff --git a/templates/tower_cli.cfg.j2 b/templates/tower_cli.cfg.j2 deleted file mode 100644 index eb021ab..0000000 --- a/templates/tower_cli.cfg.j2 +++ /dev/null @@ -1,5 +0,0 @@ -host = https://{{ tower_config.host }} -verify_ssl = {{ tower_config.verify_ssl|bool }} -username = {{ tower_config.username }} -password = {{ tower_config.password }} -format = {{ tower_config.format }} diff --git a/tests/custom_travis_wait.sh b/tests/custom_travis_wait.sh deleted file mode 100755 index 1197b72..0000000 --- a/tests/custom_travis_wait.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -# Add a custom wait time (limit value, in seconds). -# -# Chose to use a custom script instead of travis_wait, since travis_wait eats -# logged output then spits it out at the end. - -set -e -set -u - -command=$1 - -# Launch command in the background. -${command} & - -# Ping every second. -seconds=0 -limit=45*60 -while kill -0 $! >/dev/null 2>&1; -do - echo -n -e " \b" - if [ $seconds == $limit ]; then - break; - fi - seconds=$((seconds + 1)) - sleep 1 -done diff --git a/tests/requirements.yml b/tests/requirements.yml deleted file mode 100644 index 730dbcd..0000000 --- a/tests/requirements.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- src: victorock.tower_setup -- src: victorock.download -- src: geerlingguy.pip diff --git a/vars/main.yml b/vars/main.yml index b739f91..0ddda49 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,3 +1,4 @@ +--- _tower_config: host: https://localhost username: admin @@ -13,4 +14,4 @@ _tower_config_organization: projects: [] permissions: [] inventories: [] - credentials: [] \ No newline at end of file + credentials: []