Managing configurations by using Ansible integration
Configure Ansible integration in Satellite and use Ansible roles and playbooks to configure your hosts
Abstract
Providing feedback on Red Hat documentation
We appreciate your feedback on our documentation. Let us know how we can improve it.
Use the Create Issue form in Red Hat Jira to provide your feedback. The Jira issue is created in the Red Hat Satellite Jira project, where you can track its progress.
Procedure
- Log in to Content from id.atlassian.com is not included.Atlassian Jira.
- Click the following link: Content from redhat.atlassian.net is not included.Create Issue.
- Complete the Summary, Description, and Reporter fields. In the Description field, include the documentation URL, chapter or section number, and a detailed description of the issue. Do not modify any other fields in the form.
- Click Create.
Chapter 1. Configuration management with Ansible in Satellite
By using Ansible as a configuration management tool in Satellite, you can define the desired state of your hosts and maintain it over time. Satellite combines Ansible features with recurring job runs and centralized orchestration, which helps you manage host configurations consistently.
1.1. High-level steps for configuration management with Ansible
You use Ansible roles to define the desired state of the hosts registered to Satellite. Running the roles enforces the configuration.
Configuration management with Ansible involves the following high-level steps:
- Import Ansible roles into Satellite.
- Assign specific roles to a host or host group.
- Optional: Override Ansible variables per host or host group in Satellite.
- Run the roles on the host or host group.
As a result, your hosts maintain a consistent configuration over time. The Ansible roles become a part of their definition.
Running an Ansible role on a host triggers a remote execution job in the background but the use case is different. The typical use case for a remote execution job is to run an ad-hoc task or orchestration. The typical use case for configuration management by using Ansible and Ansible roles is long-term state management.
Additional resources
1.2. Ansible versions supported for integration with Satellite
Satellite repositories include ansible-core as a packaged dependency, which determines the version supported for integration with Satellite.
Satellite repositories include ansible-core as a packaged dependency for Ansible integration with Satellite Server and Capsule Servers. The supported version of Ansible is ansible-core 2.16.
Chapter 2. Enabling the Ansible plugin
Before you can use Ansible for configuration management in Satellite, enable Ansible integration in Satellite and on all Capsule Servers that you want to use to run Ansible roles on hosts.
Procedure
On all Capsule Servers that you want to use to run Ansible roles on hosts, enable the Ansible plugin:
# satellite-installer --enable-foreman-proxy-plugin-ansible
Chapter 3. Configuring Ansible definitions to apply to hosts
Configure and organize Ansible definitions in Satellite to control which configurations are available for your hosts. Keeping definitions organized helps you apply consistent changes across your hosts.
3.1. Adding Red Hat Enterprise Linux System Roles
Red Hat Enterprise Linux System Roles is a configuration interface to remotely manage Red Hat Enterprise Linux servers. You can use Red Hat Enterprise Linux System Roles to add Ansible roles in Satellite.
Support levels for some of the Red Hat Enterprise Linux System Roles might be in Technology Preview. For up-to-date information about support levels and general information about Red Hat Enterprise Linux System Roles, see Red Hat Enterprise Linux System Roles.
Before subscribing to the Extras or AppStream channels, see Red Hat Enterprise Linux Extras Product Lifecycle or Red Hat Enterprise Linux Application Streams Life Cycle.
Procedure
Ensure that the following repository is enabled:
On Red Hat Enterprise Linux 10, 9, or 8, ensure that the AppStream repository is enabled:
# subscription-manager repos --enable=rhel-10-for-x86_64-appstream-rpms # subscription-manager repos --enable=rhel-9-for-x86_64-appstream-rpms # subscription-manager repos --enable=rhel-8-for-x86_64-appstream-rpms
You must enable an AppStream repository that is designated for your architecture. For more information, see RHEL 8 repositories.
On Red Hat Enterprise Linux 7, ensure that the Extras repository is enabled:
# subscription-manager repos --enable=rhel-7-server-extras-rpms
Install the
rhel-system-rolespackage:# satellite-maintain packages install rhel-system-roles
The
rhel-system-rolespackage downloads to/usr/share/ansible/roles/. You can view and make any modifications that you want to the files before you import.- In the Satellite web UI, navigate to Configure > Ansible > Roles.
- Click the Capsule that contains the roles that you want to import.
From the list of Ansible roles, select the checkbox of the roles you want to import, and then click Update.
You can now assign Ansible roles to hosts or host groups. For more information, see Section 3.5, “Assigning Ansible roles to an existing host”.
You can also add the modules contained in these roles to your Ansible Playbooks by adding them to Ansible Job Templates. You must include the
hosts:allline in the job template. For more information, see Red Hat Enterprise Linux (RHEL) System Roles.
3.2. Importing Ansible roles and variables
You can import Ansible roles and variables from the Ansible paths on Satellite Server or Capsule Servers that have Ansible enabled.
Procedure
Place the roles and variables in the appropriate Ansible paths on all Capsules from where you want to use the roles. For more information, see Appendix A, Ansible role and collection paths in Satellite.
If you want to use custom or third party Ansible roles, ensure to configure an external version control system to synchronize roles between Satellite Server and Capsule Servers.
- In the Satellite web UI, navigate to Configure > Ansible > Roles.
- Click Import to select the Capsule from which you want to import.
- Select the roles that you want to import.
- Click Submit.
3.3. Overriding Ansible variables in Satellite
You can use Satellite to override Ansible variables for roles imported into Satellite. This helps you customize the behavior of imported roles to fit your specific needs.
If you use an Ansible role to run a task as a user that is not the Effective User, there is a strict order of precedence for overriding Ansible variables. To ensure the variable that you override follows the correct order of precedence, see Content from docs.ansible.com is not included.Variable precedence: Where should I put a variable?.
Prerequisites
- Ansible variables are available in Satellite. For more information, see Section 3.2, “Importing Ansible roles and variables”
- To use overridden Ansible variables, your user account has a role that allows viewing the attributes that are matched against hosts.
Procedure
- In the Satellite web UI, navigate to Configure > Ansible > Variables.
- Select the Ansible variable that you want to override and manage with Satellite.
- In the Default Behavior area, select the Override checkbox.
- In the Parameter Type field, select the value type for validation such as string or boolean. The types array and hash have further options for handling upon a variable match. For more information, see the Prioritize Attribute Order area below.
- In the Default Value field, enter the default value that you want to use if there is no match for the variable.
- Optional: If you do not want to display the value of the variable as plain text in the Satellite web UI, select the Hidden Value checkbox to display the content of the variable as asterisks. This is useful for sensitive values such as passwords or secret tokens.
Optional: Expand the Optional Input Validator area and specify conditions that will be used to validate concrete values of the variable:
- Select Required if you want to enforce users to fill in this variable.
In the Validator Type field, select how the value will be validated:
-
list– The value will be validated against an enumeration of allowed values. -
regex– The value will be validated against a regular expression pattern.
-
Optional: In the Prioritize Attribute Order area, specify the order of priority to match an override with a host by host attributes. Order at the top takes higher precedence. The first match wins.
You can combine multiple attributes into a single matcher key using a comma as the AND operation. For example, the matcher key of
hostgroup, environmentwould expect matchers such ashostgroup = "web servers"ANDenvironment = production.If you use the parameter type array or hash, you can further set:
- Merge Overrides – Merges members of the arrays/hashes instead of replacing the whole array or hash. If the hashes contain the same key, the value is overwritten by the value of the host.
- Merge Default – Adds the default value to the array or hash.
- Avoid Duplicates – Ensures that the values in the array or hash are unique.
- Optional: Expand the Specify Matchers area and specify criteria for selecting hosts on which the variable overrides.
- To save the override settings, click Submit.
To use the Ansible variable, add the variable as a parameter to your host or host group, or add the variable as a global parameter:
To add the variable to a host:
- In the Satellite web UI, navigate to Hosts > All Hosts and select the host that you want to use.
- Click the Ansible tab, and in the Variables area, click the pencil icon to edit the value of the variable.
- Click the tick icon to accept the value of the changed variable or the cross icon to cancel the change.
To add the variable to a host group:
- In the Satellite web UI, navigate to Configure > Host Groups, and select the host group that you want to use.
- Click the Parameters tab, and in the Host Group Parameters area, click Add Parameter.
- In the Name field, add the Ansible variable name.
- From the Type list, select the type of the variable for validation.
- In the Value field, enter the value for the variable.
To add the variable as a global parameter:
- In the Satellite web UI, navigate to Configure > Global Parameters, and click Create Parameter.
- In the Name field, add the Ansible variable name.
- From the Type list, select the type of the variable for validation.
- In the Value field, enter the value for the variable.
- Optional: If you do not want to display the Ansible variable in plain text, select the Hidden Values checkbox to display the content of the variable as asterisks in the Satellite web UI.
3.4. Assigning Ansible roles to a host group
You can assign a previously imported Ansible role to a host group. This enables Satellite to apply the configuration defined by the role when you provision a new host by using the host group.
Procedure
- In the Satellite web UI, navigate to Configure > Host Groups.
- Click the host group name to which you want to assign an Ansible role.
- On the Ansible Roles tab, select the role that you want to add from the Available Ansible Roles list.
- Click the + icon to add the role to the host group. You can add more than one role.
- Click Submit.
3.5. Assigning Ansible roles to an existing host
You can assign a previously imported Ansible role to an existing host. This enables Satellite to apply the configuration defined by the role when you run the Ansible roles on the host.
Procedure
- In the Satellite web UI, navigate to Hosts > All Hosts.
- Select the host and click Edit.
- On the Ansible Roles tab, select the role that you want to add from the Available Ansible Roles list.
- Click the + icon to add the role to the host. You can add more than one role.
- Click Submit.
- Optional: On the Parameters tab, click Add Parameter to add any parameter variables that you want to pass to job templates at run time. This includes all Ansible Playbook parameters and host parameters that you want to associate with the host. To use a parameter variable with an Ansible job template, you must add a Host Parameter.
3.6. Changing the order of Ansible roles
Change the order of Ansible roles on a host to control how role tasks are applied. This helps prevent dependency and precedence issues during configuration runs.
Procedure
- In the Satellite web UI, navigate to Hosts > All Hosts.
- Select a host.
- Select the Ansible Roles tab.
- In the Assigned Ansible Roles area, you can change the order of the roles by dragging and dropping the roles into the preferred position.
- Click Submit to save the order of the Ansible roles.
3.7. Removing Ansible roles from a host
Remove Ansible roles from a host to stop applying configurations to the host.
Procedure
- In the Satellite web UI, navigate to Hosts > All Hosts.
- Select the host and click Edit.
- Select the Ansible Roles tab.
- In the Assigned Ansible Roles area, click the - icon to remove the role from the host. Repeat to remove more roles.
- Click Submit.
Chapter 4. Applying Ansible definitions to hosts
When a host has one or more Ansible roles assigned to it, Satellite can run the roles on the host to apply and enforce the configuration state that the roles define.
4.1. Running Ansible roles on a host
Run Ansible roles on a host through the Satellite web UI to apply the assigned configuration immediately. This helps you verify and enforce the intended state of the host.
Prerequisites
- The public SSH key from Capsule is available on the host. For more information, see Distributing SSH keys for remote execution in Managing hosts.
Procedure
- In the Satellite web UI, navigate to Hosts > All Hosts.
- Select the host on which you want to run the assigned Ansible roles.
- From the Schedule a job menu, select Run Ansible roles.
Verification
- You can view the status of your Ansible job by navigating to Monitor > Jobs.
4.2. Running Ansible roles on a host group
When a host group has one or more Ansible roles assigned to it, Satellite can run the roles on all hosts in the host group at once to apply and enforce the configuration state that the roles define.
Prerequisites
- The public SSH key from Capsule is available on the hosts in the host group. For more information, see Distributing SSH keys for remote execution in Managing hosts.
Procedure
- In the Satellite web UI, navigate to Configure > Host Groups.
- From the list in the Actions column for the host group, select Run all Ansible roles.
- You can view the status of your Ansible job on the Run Ansible roles page. Click Rerun to rerun a job.
4.3. Configuring a host to run Ansible roles in check mode
Run Ansible roles in check mode through the Satellite web UI to preview changes before applying them. This helps you reduce risk when validating role behavior on a host.
Procedure
- In the Satellite web UI, navigate to Hosts > All Hosts.
- Click Edit for the host you want to enable check mode for.
-
In the Parameters tab, ensure that the host has a parameter named
ansible_roles_check_modewith typebooleanset totrue. - Click Submit.
Chapter 5. Using Ansible Vault with Satellite
You can encrypt sensitive Ansible data files using the Ansible Vault tool and configure Ansible to access the encrypted files using a password stored in a file.
Procedure
-
If you customized
/etc/ansible/ansible.cfg, copy your configuration from/etc/ansible/ansible.cfgto/usr/share/foreman-proxy/.ansible.cfg. Encrypt the sensitive file using the
ansible-vaultcommand:# ansible-vault encrypt /etc/ansible/roles/Role_Name/vars/main.ymlNote that
ansible-vaultchanges the file permissions to600.Change the group and permissions of the encrypted file to ensure that the
foreman-proxyuser can read it:# chgrp foreman-proxy /etc/ansible/roles/Role_Name/vars/main.yml # chmod 0640 /etc/ansible/roles/Role_Name/vars/main.yml
-
Create the
/usr/share/foreman-proxy/.ansible_vault_passwordfile and enter the Vault password into it. Change the user and permissions of the
.ansible_vault_passwordfile to ensure that only theforeman-proxyuser can read it:# chown foreman-proxy:foreman-proxy /usr/share/foreman-proxy/.ansible_vault_password # chmod 0400 /usr/share/foreman-proxy/.ansible_vault_password
Add the path of the Vault password file to the
[defaults]section in/usr/share/foreman-proxy/.ansible.cfg:[defaults] vault_password_file = /usr/share/foreman-proxy/.ansible_vault_password
The path to the Vault password file must be absolute.
Chapter 6. Integrating Red Hat Satellite and Ansible Automation Platform
You can integrate Red Hat Satellite and Ansible Automation Platform to use Satellite Server as a dynamic inventory source for Ansible Automation Platform. When provisioning new hosts from Satellite Server, you can use the provisioning callback function to trigger playbook runs from Ansible Automation Platform.
6.1. Adding Satellite Server to Ansible Automation Platform as a dynamic inventory item
To add Satellite Server to Ansible Automation Platform as a dynamic inventory item, you must create a credential for a Satellite Server user on Ansible Automation Platform, add an Ansible Automation Platform user to the credential, and then configure an inventory source.
Prerequisites
- If your Satellite deployment is large, for example, managing tens of thousands of hosts, using a non-admin user can negatively impact performance because of time penalties that accrue during authorization checks. For large deployments, consider using an admin user.
-
For non-admin users, the
Ansible Tower Inventory Readerrole is assigned to your Satellite Server user. For more information about managing users, roles, and permission filters, see Creating and managing roles in Administering Red Hat Satellite. - Your Satellite Server and Ansible Automation Platform are hosted on the same network or subnet.
Procedure
In the Ansible Automation Platform web UI, create a credential for your Satellite. For more information about creating credentials, see Creating new credentials and Red Hat Satellite 6 credential type in Red Hat Ansible Automation Platform documentation.
Table 6.1. Satellite credentials
Credential Type: Red Hat Satellite 6 Satellite URL:
https://satellite.example.com
Username:
The username of the Satellite user with the integration role.
Password:
The password of the Satellite user.
- Add an Ansible Automation Platform user to the new credential. For more information about adding a user to a credential, see Adding new users and job templates to existing credentials in Red Hat Ansible Automation Platform documentation.
Add a new inventory. For more information, see Add a new inventory in Red Hat Ansible Automation Platform documentation.
In the new inventory, add Satellite Server as the inventory source, specifying the following inventory source options.
Table 6.2. Inventory source options
Source Red Hat Satellite 6 Credential
The credential you create for Satellite Server.
Overwrite
Select
Overwrite Variables
Select
Update on Launch
Select
Cache Timeout
90
- Ensure that you synchronize the source that you add.
6.2. Configuring provisioning callback for a host
When you create hosts in Satellite, you can use Ansible Automation Platform to run playbooks to configure your newly created hosts. This is called provisioning callback in Ansible Automation Platform.
The provisioning callback function triggers a playbook run from Ansible Automation Platform as part of the provisioning process. The playbook configures the host after the provisioning process.
In Satellite Server, the Kickstart Default and Kickstart Default Finish templates include three snippets:
-
ansible_provisioning_callback -
ansible_tower_callback_script -
ansible_tower_callback_service
You can add parameters to hosts or host groups to provide the credentials that these snippets can use to run Ansible Playbooks on your newly created hosts.
Prerequisites
- Satellite is added as a dynamic inventory in Ansible Automation Platform. For more information, see Chapter 6, Integrating Red Hat Satellite and Ansible Automation Platform.
Procedure
In the Ansible Automation Platform web UI, complete the following tasks:
- Create a machine credential for your new host. Ensure that you enter the same password in the credential that you plan to assign to the host that you create in Satellite. For more information, see Managing user credentials in Red Hat Ansible Automation Platform documentation.
- Create a project. For more information, see Projects in Red Hat Ansible Automation Platform documentation.
- Add a job template to your project. In your job template, you must enable provisioning callbacks, generate the host configuration key, and note the template_ID of your job template. For more information, see Job templates in Red Hat Ansible Automation Platform documentation.
- In the Satellite web UI, navigate to Configure > Host Group.
- Create a host group or edit an existing host group.
- In the Host Group window, click the Parameters tab.
- Click Add Parameter.
Enter the following information for each new parameter:
Table 6.3. Host parameters
Name Value Description ansible_tower_provisioningtrue
Enables Provisioning Callback.
ansible_tower_api_urlContent from aap.example.com is not included.https://aap.example.com/api/controller/v2
Defines the URL of your Ansible Automation Platform, including the required API path. For older versions of Ansible Automation Platform, use
/api/v2instead of/api/controller/v2. If unsure, check the API endpoints of your instance to verify the correct path.ansible_job_template_idtemplate_ID
The ID of your provisioning template that you can find in the URL of the template:
/templates/job_template/5.ansible_host_config_keyconfig_KEY
The host configuration key that your job template generates in Ansible Automation Platform.
- Click Submit.
- Create a host using the host group.
On your new host, start the
ansible-callbackservice:# systemctl start ansible-callback
On your new host, check the the status of the
ansible-callbackservice:# systemctl status ansible-callback
Provisioning callback is configured correctly if the command returns the following output:
satellite.example.com systemd[1]: Started Provisioning callback to Ansible Automation Platform...
NoteFor manual provisioning callback, you can use the provisioning callback URL and the host configuration key from a host to call Ansible Automation Platform:
$ curl \ --data curl \ --data host_config_key=My_Host_Config_Key \ --show-error \ --silent \ https://aap.example.com/api/v2/job_templates/8/callback/
Ensure that you use
httpswhen you enter the provisioning callback URL.This triggers the playbook run specified in the template against the host.
Additional resources
Appendix A. Ansible role and collection paths in Satellite
Satellite imports and runs Ansible roles and collections from specific system paths. System-installed roles and collections are located in /usr/share/ansible, while custom roles and collections should be placed in /etc/ansible.
Satellite imports and runs Ansible roles from the following paths:
-
/etc/ansible/roles -
/usr/share/ansible/roles -
/etc/ansible/collections -
/usr/share/ansible/collections
Roles and collections from installed packages are placed under /usr/share/ansible. If you want to add custom roles or collections, place them under /etc/ansible.
Note that Red Hat provides support only for Ansible roles and collections obtained from Red Hat.
Appendix B. Customizing Ansible configuration
Satellite manages essential Ansible configuration that is required for Ansible integration with Satellite. However, you can customize other Ansible configuration options as usual.
Satellite stores the essential Ansible configuration as environment variables in /etc/foreman-proxy/ansible.env. This file is managed by satellite-installer.
Ansible reads configuration from a configuration file and the environment provided by Capsule. If you need to customize Ansible configuration, you can do so in the system-wide /etc/ansible/ansible.cfg file or in the /usr/share/foreman-proxy/.ansible.cfg file in the home directory of the foreman-proxy user. Note that if you use /usr/share/foreman-proxy/.ansible.cfg, Ansible spawned by Satellite ignores configuration in /etc/ansible/ansible.cfg.
Note that environment variables take precedence over values in ansible.cfg, which ensures that the essential configuration required by Satellite is retained.
The following table lists the essential Ansible configuration options managed by Satellite.
Table B.1. Essential Ansible configuration
| Environment Variable | Config Key | Description |
|---|---|---|
| ANSIBLE_CALLBACKS_ENABLED | callbacks_enabled |
Enables callback to Satellite; equivalent to |
| ANSIBLE_CALLBACK_WHITELIST | callback_whitelist |
Enables callback to Satellite; equivalent to |
| ANSIBLE_COLLECTIONS_PATHS | collections_paths | List of paths to Ansible collections |
| ANSIBLE_HOST_KEY_CHECKING | host_key_checking | Disables checking of host keys during SSH connection |
| ANSIBLE_LOCAL_TEMP | local_tmp | Temporary directory on Capsule |
| ANSIBLE_ROLES_PATH | roles_path | List of paths to Ansible roles |
| ANSIBLE_SSH_ARGS | ssh_args | Arguments passed to SSH connection |
Additional resources