controller_configuration icon indicating copy to clipboard operation
controller_configuration copied to clipboard

Compatibility with awx.awx.export / awxkit

Open luckylittle opened this issue 2 years ago • 2 comments

Please make this role compatible with awx.awx.export / awxkit. It does not work out of the box:

Steps to reproduce:

  1. Run the export playbook:
---
- hosts: localhost
  tasks:
  - name: Export all assets
    awx.awx.export:
      organizations: 'all'
    register: orgs_register

  - name: Store organizations as YAML in ./configs
    ansible.builtin.copy:
      content: "{{ orgs_register.assets | to_yaml }}"
      dest: "/home/redhat/Projects/awxkit/configs/organizations.yml"
  1. It exports the following example file:
organizations:
- default_environment: null
  description: This is one Business Unit in DEV
  max_hosts: 0
  name: NAB_BU_1_dev
  natural_key: {name: NAB_BU_1_dev, type: organization}
  related:
    execution_environments: []
    galaxy_credentials:
    - credential_type: {kind: galaxy, name: Ansible Galaxy/Automation Hub API Token,
        type: credential_type}
      name: Ansible Galaxy
      organization: null
      type: credential
    notification_templates: []
    notification_templates_approvals: []
    notification_templates_error: []
    notification_templates_started: []
    notification_templates_success: []
- default_environment: null
  description: Another business unit, but in PROD
  max_hosts: 0
  name: NAB_BU_2_prod
  natural_key: {name: NAB_BU_2_prod, type: organization}
  related:
    execution_environments: []
    galaxy_credentials:
    - credential_type: {kind: galaxy, name: Ansible Galaxy/Automation Hub API Token,
        type: credential_type}
      name: Ansible Galaxy
      organization: null
      type: credential
    notification_templates: []
    notification_templates_approvals: []
    notification_templates_error: []
    notification_templates_started: []
    notification_templates_success: []
  1. Remove these two organizations from AAP

  2. Run the playbook to configure AAP using the export from step 1:

---
- name: Playbook to configure Ansible Controller
  hosts: localhost
  connection: local
  collections:
    - redhat_cop.controller_configuration
  pre_tasks:

    - 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: organizations, when: controller_organizations is defined, tags: organizations}

Expected result: The role is compatible with awxkit. Two organizations will be re-added.

Actual result: Nothing happens, because the top level list is called the organizations: and the role expects controller_organizations:. When you add the prefix and re-run the playbook, it does import them successfully.

OS: Red Hat Enterprise Linux release v8.6 (Ootpa) Ansible: core v2.12.2 awxkit: v21.3.0 redhat_cop.controller_configuration: v2.1.6

luckylittle avatar Jul 29 '22 03:07 luckylittle

This is a big change that would break anyones older code. At this time I don't think we see the value there but if the demand rises that may change. I will leave this issue open and allow people to +1 if they would also like this change.

djdanielsson avatar Aug 08 '22 13:08 djdanielsson

checkout filetree_create role, this does what you are looking for somewhat. We have talked about creating a basic export role as well that would fit our variables naming convention.

djdanielsson avatar Sep 30 '22 00:09 djdanielsson

Closing this issue as it is now resolved by the above merge

sean-m-sullivan avatar Apr 23 '23 02:04 sean-m-sullivan