Skip to content

Commit

Permalink
updated README.md. Added ansible-playbook command example
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarmu committed Nov 8, 2023
1 parent b8bfbe6 commit 42f547a
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 2 deletions.
110 changes: 110 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,116 @@ The awx command line can export json that is compatible with this collection.
In addition there is an awx.awx/ansible.controller export module that use the awx command line to export.
More details can be found [here](EXPORT_README.md)

There's another possible way to export the controller configuration, which is using the `filetree_create` module. It can generate output files in two different ways:

- **Structured output**:

The output files are distributed in separate directories, by organization first, and then by object type. Into each of these directories, one file per object is generated. This way allows to organize the files using different criteria, for example, by funcionalities or applications.

The expotation can be triggered with the following command:

```console
ansible-playbook -i localhost, filetree_create.yml -e '{controller_validate_certs: false, controller_hostname: localhost:8443, controller_username: admin, controller_password: password}'
```

One example of this approach follows:

```console
/tmp/filetree_output_distributted
├── current_credential_types.yaml
├── current_execution_environments.yaml
├── current_instance_groups.yaml
├── current_settings.yaml
├── Default
│   ├── applications
│   │   ├── 23_controller_application-app2.yaml
│   │   └── 24_controller_application-app3.yaml
│   ├── credentials
│   │   ├── 82_Demo Credential.yaml
│   │   └── 84_Demo Custom Credential.yaml
│   ├── current_organization.yaml
│   ├── inventories
│   │   ├── Demo Inventory
│   │   │   └── 81_Demo Inventory.yaml
│   │   └── Test Inventory - Smart
│   │   ├── 78_Test Inventory - Smart.yaml
│   │   └── current_hosts.yaml
│   ├── job_templates
│   │   ├── 177_test-template-1.yaml
│   │   └── 190_Demo Job Template.yaml
│   ├── labels
│   │   ├── 52_Prod.yaml
│   │   ├── 53_differential.yaml
│   ├── notification_templates
│   │   ├── Email notification differential.yaml
│   │   └── Email notification.yaml
│   ├── projects
│   │   ├── 169_Test Project.yaml
│   │   ├── 170_Demo Project.yaml
│   ├── teams
│   │   ├── 28_satellite-qe.yaml
│   │   └── 29_tower-team.yaml
│   └── workflow_job_templates
│   ├── 191_Simple workflow schema.yaml
│   └── 200_Complicated workflow schema.yaml
├── ORGANIZATIONLESS
│   ├── credentials
│   │   ├── 2_Ansible Galaxy.yaml
│   │   └── 3_Default Execution Environment Registry Credential.yaml
│   └── users
│   ├── admin.yaml
│   ├── controller_user.yaml
├── schedules
│   ├── 1_Cleanup Job Schedule.yaml
│   ├── 2_Cleanup Activity Schedule.yaml
│   ├── 4_Cleanup Expired Sessions.yaml
│   ├── 52_Demo Schedule.yaml
│   ├── 53_Demo Schedule 2.yaml
│   └── 5_Cleanup Expired OAuth 2 Tokens.yaml
├── team_roles
│   ├── current_roles_satellite-qe.yaml
│   └── current_roles_tower-team.yaml
└── user_roles
└── current_roles_controller_user.yaml
```

- **Flatten files**:

The output files are all located in the same directory. Each file contains a YAML list with all the objects belonging to the same object type. This output format allows to load all the objects both from the standard Ansible `group_vars` and from the `infra.controller_configuration.filetree_read` role.

The expotation can be triggered with the following command:

```console
ansible-playbook -i localhost, filetree_create.yml -e '{controller_validate_certs: false, controller_hostname: localhost:8443, controller_username: admin, controller_password: password, flatten_output: true}'
```

One example of this approach follows:

```console
/tmp/filetree_output_flatten
├── applications.yaml
├── credentials.yaml
├── current_credential_types.yaml
├── current_execution_environments.yaml
├── current_instance_groups.yaml
├── current_settings.yaml
├── groups.yaml
├── hosts.yaml
├── inventories.yaml
├── inventory_sources.yaml
├── job_templates.yaml
├── labels.yaml
├── notification_templates.yaml
├── organizations.yaml
├── projects.yaml
├── schedules.yaml
├── team_roles.yaml
├── teams.yaml
├── user_roles.yaml
├── users.yaml
└── workflow_job_templates.yaml
```

### Template Example

A Template to use in order to start using the collections can be found [here](https://github.com/redhat-cop/aap_configuration_template)
Expand Down
10 changes: 8 additions & 2 deletions playbooks/flatten_filetree_create_output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@

- name: "Write all the objects to the corresponding file"
ansible.builtin.copy:
dest: "{{ filetree_create_output_dir }}_flatten/{{ item.name }}.yaml"
dest: "{{ filetree_create_output_dir }}_flatten/{{ object_type.name }}.yaml"
mode: "0644"
content: |
---
{{ item.value | to_nice_yaml(indent=2) }}
{{ object_type.value | to_nice_yaml(indent=2) }}
...
loop_control:
loop_var: object_type
loop:
- name: controller_settings
value: "{{ controller_settings }}"
Expand Down Expand Up @@ -86,3 +88,7 @@
- name: controller_roles
value: "{{ controller_roles }}"
...
# Sample usage:
#
# ansible-playbook infra.controller_configuration.flatten_filetree_create_output.yaml -e '{filetree_create_output_dir: /tmp/filetree_output}'
#

0 comments on commit 42f547a

Please sign in to comment.