Created
July 29, 2022 05:36
-
-
Save luckylittle/f7a11a15f15036355457c0c7c5c4ea25 to your computer and use it in GitHub Desktop.
Complete backup of Red Hat Ansible Automation Platform into YAML files ready to be used by redhat_cop.controller_configuration collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Playbook to Export all resources from the AAP into YAML files using awxkit | |
hosts: localhost | |
vars: | |
controller_configuration_path: "/home/lmaly/Projects/awxkit" | |
tasks: | |
- name: Export all users assets | |
awx.awx.export: | |
users: 'all' | |
register: "users" | |
- name: Store the users assets | |
ansible.builtin.copy: | |
content: "{{ users.assets | to_yaml }}" | |
dest: "{{ controller_configuration_path }}/configs/users.yml" | |
- name: Export all organizations assets | |
awx.awx.export: | |
organizations: 'all' | |
register: "organizations" | |
- name: Store the organizations assets | |
ansible.builtin.copy: | |
content: "{{ organizations.assets | to_yaml }}" | |
dest: "{{ controller_configuration_path }}/configs/organizations.yml" | |
- name: Export all teams assets | |
awx.awx.export: | |
teams: 'all' | |
register: "teams" | |
- name: Store the teams assets | |
ansible.builtin.copy: | |
content: "{{ teams.assets | to_yaml }}" | |
dest: "{{ controller_configuration_path }}/configs/teams.yml" | |
- name: Export all credential_types assets | |
awx.awx.export: | |
credential_types: 'all' | |
register: "credential_types" | |
- name: Store the credential_types assets | |
ansible.builtin.copy: | |
content: "{{ credential_types.assets | to_yaml }}" | |
dest: "{{ controller_configuration_path }}/configs/credential_types.yml" | |
- name: Export all credentials assets | |
awx.awx.export: | |
credentials: 'all' | |
register: "credentials" | |
- name: Store the credentials assets | |
ansible.builtin.copy: | |
content: "{{ credentials.assets | to_yaml }}" | |
dest: "{{ controller_configuration_path }}/configs/credentials.yml" | |
- name: Export all notification_templates assets | |
awx.awx.export: | |
notification_templates: 'all' | |
register: "notification_templates" | |
- name: Store the notification_templates assets | |
ansible.builtin.copy: | |
content: "{{ notification_templates.assets | to_yaml }}" | |
dest: "{{ controller_configuration_path }}/configs/notification_templates.yml" | |
- name: Export all projects assets | |
awx.awx.export: | |
projects: 'all' | |
register: "projects" | |
- name: Store the projects assets | |
ansible.builtin.copy: | |
content: "{{ projects.assets | to_yaml }}" | |
dest: "{{ controller_configuration_path }}/configs/projects.yml" | |
- name: Export all inventory assets | |
awx.awx.export: | |
inventory: 'all' | |
register: "inventory" | |
- name: Store the inventory assets | |
ansible.builtin.copy: | |
content: "{{ inventory.assets | to_yaml }}" | |
dest: "{{ controller_configuration_path }}/configs/inventory.yml" | |
- name: Export all inventory_sources assets | |
awx.awx.export: | |
inventory_sources: 'all' | |
register: "inventory_sources" | |
- name: Store the inventory_sources assets | |
ansible.builtin.copy: | |
content: "{{ inventory_sources.assets | to_yaml }}" | |
dest: "{{ controller_configuration_path }}/configs/inventory_sources.yml" | |
- name: Export all job_templates assets | |
awx.awx.export: | |
job_templates: 'all' | |
register: "job_templates" | |
- name: Store the job_templates assets | |
ansible.builtin.copy: | |
content: "{{ job_templates.assets | to_yaml }}" | |
dest: "{{ controller_configuration_path }}/configs/job_templates.yml" | |
- name: Export all workflow_job_templates assets | |
awx.awx.export: | |
workflow_job_templates: 'all' | |
register: "workflow_job_templates" | |
- name: Store the workflow_job_templates assets | |
ansible.builtin.copy: | |
content: "{{ workflow_job_templates.assets | to_yaml }}" | |
dest: "{{ controller_configuration_path }}/configs/workflow_job_templates.yml" | |
- name: Export all execution_environments assets | |
awx.awx.export: | |
execution_environments: 'all' | |
register: "execution_environments" | |
- name: Store the execution_environments assets | |
ansible.builtin.copy: | |
content: "{{ execution_environments.assets | to_yaml }}" | |
dest: "{{ controller_configuration_path }}/configs/execution_environments.yml" | |
- name: Export all applications assets | |
awx.awx.export: | |
applications: 'all' | |
register: "applications" | |
- name: Store the applications assets | |
ansible.builtin.copy: | |
content: "{{ applications.assets | to_yaml }}" | |
dest: "{{ controller_configuration_path }}/configs/applications.yml" | |
- name: Export all schedules assets | |
awx.awx.export: | |
schedules: 'all' | |
register: "schedules" | |
- name: Store the schedules assets | |
ansible.builtin.copy: | |
content: "{{ schedules.assets | to_yaml }}" | |
dest: "{{ controller_configuration_path }}/configs/schedules.yml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Playbook to configure Ansible Controller using previously created export in awxkit | |
hosts: localhost | |
collections: | |
- awx.awx | |
- redhat_cop.controller_configuration | |
vars: | |
controller_configuration_path: "/home/lmaly/Projects/awxkit" | |
pre_tasks: | |
- name: Transform the awxkit export files for the controller_configuration role | |
# See the reason: https://github.com/redhat-cop/controller_configuration/issues/332 | |
ansible.builtin.replace: | |
path: "{{ item }}" | |
regexp: "^{{ item | basename | split('.') | first }}:" | |
replace: "controller_{{ item | basename | split('.') | first }}:" | |
with_fileglob: | |
- "{{ controller_configuration_path }}/configs/*" | |
- name: Include vars from configs directory | |
include_vars: | |
dir: "{{ controller_configs_dir | default((lookup('env','CONTROLLER_CONFIGS_DIR') == '') | ternary('./configs', lookup('env','CONTROLLER_CONFIGS_DIR'))) }}" | |
ignore_files: [controller_config.yml.template] | |
extensions: ["yml"] | |
tags: | |
- always | |
roles: | |
- {role: applications, when: controller_applications is defined, tags: applications} | |
- {role: credential_types, when: controller_credential_types is defined, tags: credential_types} | |
- {role: credentials, when: controller_credentials is defined, tags: credentials} | |
- {role: execution_environments, when: execution_environments is defined, tags: execution_environments} | |
- {role: inventories, when: controller_inventories is defined, tags: inventories} | |
- {role: inventory_sources, when: controller_inventory_sources is defined, tags: inventory_sources} | |
- {role: notification_templates, when: controller_notifications is defined, tags: notification_templates} | |
- {role: organizations, when: controller_organizations is defined, tags: organizations} | |
- {role: schedules, when: schedules is defined, tags: schedules} | |
- {role: teams, when: controller_teams is defined, tags: teams} | |
- {role: users, when: controller_user_accounts is defined, tags: users} | |
- {role: projects, when: controller_projects is defined, tags: projects} | |
- {role: project_update, when: controller_projects is defined, tags: projects} | |
- {role: job_templates, when: controller_templates is defined, tags: job_templates} | |
- {role: workflow_job_templates, when: controller_workflows is defined, tags: workflow_job_templates} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment