Configuration as Code
Set and manage your Ansible Automation Platform Controller with configuration files
Abstract
Providing feedback on Red Hat documentation Copy linkLink copied to clipboard!
If you have a suggestion to improve this documentation, or find an error, you can contact technical support at https://access.redhat.com to open a request.
Chapter 1. Setting up your automation environment for Configuration as Code Copy linkLink copied to clipboard!
Configuration as Code is a way of working where you define and manage the configuration of the Ansible Automation Platform itself using the version-controlled configuration files (such as YAML, or JSON), instead of clicking through the web UI.
As an Ansible content developer, you can use the Configuration as Code approach to apply settings on your automation controller to get the following benefits:
- Predictable job behavior
- Easier and faster scaling to new clusters
- Change history with diffs and rollback capability thanks to version control support
- Faster recovery after outages or migrations
- Reduced risk of errors because changes flow through CI/CD pipelines and pull requests, where peer reviews and automated testing are applied
Prerequisites
- You have a Git account.
- Your platform gateway instance is accessible.
-
You built and registered your own execution environment. Alternatively, you have available the supported execution environment to run playbooks that use the
ansible.platformcollection. For more information, see Creating and using execution environments.
Procedure
- Create a new Git repository.
On your local machine, encrypt your password for platform gateway:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You encrypted the value of the
aap_passwordvariable, which you will use in the next step.Create the
/my_ansible_project/vars/all.ymlfile with variables for connecting to your Ansible Automation Platform and variables for creating Role-Based Access Control (RBAC) objects:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Compose the
/my_ansible_project/RBAC_settings.ymlplaybook, which creates RBAC objects and assigns roles to those objects:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Many values in this playbook are provided in the form of variables, such as object names, their details, Ansible Automation Platform credentials. You can easily reuse the variables throughout files in your Ansible project, which will also simplify the creation and maintenance of the project and reduce the number of errors.
Refer to the
all.ymlfile to see the expanded values of those variables. For details about the module parameters, default values, and further examples how to use the modules, see the resources on Automation hub for the ansible.platform collection.Push the variables and the playbook to your Git repository so that the automation controller can later read in the correct data.
git add . git commit -m "Provide variables and RBAC_settings.yml playbook resources for Ansible Automation Platform project" git push origin _<relevant_branch_name>_
git add . git commit -m "Provide variables and RBAC_settings.yml playbook resources for Ansible Automation Platform project" git push origin _<relevant_branch_name>_Copy to Clipboard Copied! Toggle word wrap Toggle overflow Using the platform gateway UI, create a new project with the following values:
- Name: Platform collection testing
-
Description: Automation resources to test the CaC capability of RBAC modules from the
ansible.platformcollection -
Execution Environment:
ee-supported - Organization: Default
- Source Control Type: Git
Source Control URL: https://my_git_url/my_git_repository/my_ansible_project
Create a credential for your Ansible Vault password of your encrypted
aap_passwordvariable:- Name: aap_password_vault
-
Description: Holds vault password for decrypting the value of the
aap_passwordvariable - Credential type: Vault
Vault Password: <vault_password>
Create a job template with the following values:
- Name: RBAC_settings
- Description: Create organization, team, user, and custom role RBAC objects. Assign a pre-existing role to the created team and assign a pre-existing role to the created user.
- Job type: Run
- Inventory: Demo Inventory
- Project: Platform collection testing
-
Playbook:
RBAC_settings.yml -
Execution Environment:
ee-supported Credentials: aap_password_vault | Vault
Launch the
RBAC_settingsjob template. After the template job successfully finishes, the output should be similar to the following:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The output message shows that you ran the job template against 1 target (your localhost). At the same time, you created:
- An organization.
- A team that exists within the created organization. The team was assigned some pre-existing role.
- A user that exists within the created organization. The user was assigned some pre-existing role.
- A custom role.
Verification
In the navigation panel, check that you see your created organization:
Check that you see your created team, which belongs to the organization and is assigned the correct pre-existing role:
Check that you see your created user, which belongs to the organization and is assigned the correct pre-existing role:
Check that you see your created custom role, which was assigned the permissions as specified in your
RBAC_settings.ymlplaybook: