123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- # Copyright 2020 Dell Inc. or its subsidiaries. All Rights Reserved.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- ---
- # Playbook to configure AWX
- - name: Configure AWX
- hosts: localhost
- connection: local
- gather_facts: no
- tasks:
- - name: Include vars file
- include_vars: ../vars/main.yml
- # Get Current AWX configuration
- - name: Get organization list
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- organizations list -f human
- register: organizations_list
- - name: Get project list
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- projects list -f human
- register: projects_list
- - name: Get inventory list
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- inventory list -f human
- register: inventory_list
- - name: Get template list
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- job_templates list -f human
- register: job_templates_list
- - name: If omnia-inventory exists, fetch group names in the inventory
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- groups list --inventory "{{ omnia_inventory_name }}" -f human
- register: groups_list
- when: omnia_inventory_name in inventory_list.stdout
- - name: Get schedules list
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- schedules list -f human
- register: schedules_list
- # Delete Default Configurations
- - name: Delete default organization
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- organizations delete "{{ default_org }}"
- when: default_org in organizations_list.stdout
- - name: Delete default job template
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- job_templates delete "{{ default_template }}"
- when: default_template in job_templates_list.stdout
- - name: Delete default project
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- projects delete "{{ default_projects }}"
- when: default_projects in projects_list.stdout
- # Create required configuration if not present
- - name: Create organisation
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- organizations create --name "{{ organization_name }}"
- when: organization_name not in organizations_list.stdout
- - name: Create new project
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- projects create --name "{{ project_name }}" --organization "{{ organization_name }}"
- --local_path "{{ dir_name }}"
- when: project_name not in projects_list.stdout
- - name: Create new omnia inventory
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- inventory create --name "{{ omnia_inventory_name }}" --organization "{{ organization_name }}"
- when: omnia_inventory_name not in inventory_list.stdout
- - name: Create groups in omnia inventory
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- groups create --name "{{ item }}" --inventory "{{ omnia_inventory_name }}"
- when: omnia_inventory_name not in inventory_list.stdout or item not in groups_list.stdout
- loop: "{{ group_names }}"
- - name: Create template to deploy omnia
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- job_templates create
- --name "{{ omnia_template_name }}"
- --job_type run
- --inventory "{{ omnia_inventory_name }}"
- --project "{{ project_name }}"
- --playbook "{{ omnia_playbook }}"
- --verbosity "{{ playbooks_verbosity }}"
- --ask_skip_tags_on_launch true
- when: omnia_template_name not in job_templates_list.stdout
- - name: Create template to fetch dynamic inventory
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- job_templates create
- --name "{{ inventory_template_name }}"
- --job_type run
- --inventory "{{ omnia_inventory_name }}"
- --project "{{ project_name }}"
- --playbook "{{ inventory_playbook }}"
- --verbosity "{{ playbooks_verbosity }}"
- --use_fact_cache true
- when: inventory_template_name not in job_templates_list.stdout
- - name: Schedule dynamic inventory template
- block:
- - name: Get unified job template list
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- unified_job_templates list --name "{{ inventory_template_name }}" -f human
- register: unified_job_template_list
- - name: Get job ID
- set_fact:
- job_id: "{{ unified_job_template_list.stdout | regex_search('[0-9]+') }}"
- - name: Schedule dynamic inventory job
- command: >-
- awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
- schedules create --name "{{ schedule_name }}"
- --unified_job_template="{{ job_id }}" --rrule="{{ schedule_rule }}"
- when: schedule_name not in schedules_list.stdout
|