Chapter 1. Getting started with Ansible in Satellite
Use this guide to configure Satellite to use Ansible for remote execution.
1.1. Supported Ansible versions Copy linkLink copied to clipboard!
Satellite uses Ansible as provided by the base operating system of Satellite Server or any Capsules for remote execution. Therefore, the supported version of Ansible depends on your base operating system configuration.
1.2. Configuring your Satellite to run Ansible roles Copy linkLink copied to clipboard!
In Satellite, you can import Ansible roles to help with automation of routine tasks. Ansible is enabled by default on Satellite Server.
Ansible paths
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.
The paths are configured by Satellite. For more information, see Section 1.8, “Customizing Ansible configuration”.
Procedure
- Add the roles to a directory in an Ansible path on Satellite Server and all Capsule Servers from where you want to use the roles. 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.
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- Distribute SSH keys to enable Capsules to connect to hosts using SSH. For more information, see Section 4.13, “Distributing SSH keys for remote execution”. Satellite runs Ansible roles the same way it runs remote execution jobs.
- Import the Ansible roles into Satellite.
- Proceed to Chapter 2, Using Ansible roles to automate repetitive tasks on clients.
1.3. Importing Ansible roles and variables Copy linkLink copied to clipboard!
You can import Ansible roles and variables from the Ansible paths on Satellite Server or Capsule Servers that has Ansible enabled.
Prerequisites
- Ensure that the roles and variables that you import are located in the Ansible paths on all Capsules from where you want to use the roles.
Procedure
- 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.
1.4. Overriding Ansible variables in Satellite Copy linkLink copied to clipboard!
If you run Ansible roles in Satellite, you can use Satellite to override Ansible variables for those roles.
The following procedure refers to hosts and host groups. For more information, see Managing hosts.
Precedence in overriding variables
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 Variable precedence: Where should I put a variable?.
Prerequisites
- You must have Ansible variables in Satellite. For more information, see Section 1.3, “Importing Ansible roles and variables”
- To use overridden Ansible variables, a user must have a role that allows them to see 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.
Adding 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.
Adding 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.
Adding 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.
1.5. Adding Red Hat Enterprise Linux System Roles Copy linkLink copied to clipboard!
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. Using Ansible Roles in Satellite can make configuration faster and easier.
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-rpmsYou 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-rolesThe
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 2.1, “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:all line in the job template. For more information, see Red Hat Enterprise Linux (RHEL) System Roles.
1.6. Synchronizing Ansible Collections Copy linkLink copied to clipboard!
On Satellite, you can synchronize your Ansible Collections from Private Automation Hub, console.redhat.com, and other Satellite instances. Ansible Collections will appear on Satellite as a new repository type in the Satellite web UI menu under Content after the sync.
Prerequisites
- To sync Ansible collections from Red Hat Private Automation Hub, you need to provide Satellite with an authentication token. To obtain it, go to Connect to Hub, and click Load token.
-
To sync Ansible collections from
console.redhat.com, you need an authentication token and SSO URL. To obtain them, go to Connect to Hub. Click Load token to obtain the token. Locate the SSO URL section to obtain the SSO URL.
Procedure
- In the Satellite web UI, navigate to Content > Products.
- Select the required product name.
- In the Products window, select the name of a product that you want to create a repository for.
- Click the Repositories tab, and then click New Repository.
In the Name field, enter a name for the repository.
The Label field is populated automatically based on the name.
- From the Type list, select ansible collection.
In the Upstream URL field, enter the URL for the upstream collections repository.
The URL can be any Ansible Galaxy endpoint. For example,
https://console.redhat.com/api/automation-hub/.Optional: In the Requirements.yml field, you can specify the list of collections you want to sync from the endpoint, as well as their versions.
If you do not specify the list of collections, everything from the endpoint will be synced.
--- collections: - name: my_namespace.my_collection version: 1.2.3For more information, see Installing roles and collections from the same requirements.yml file in the Galaxy User Guide.
- Optional: Deselect Sync Dependencies if you do not want Satellite to resolve and synchronize dependencies. By default, Satellite synchronizes all required dependencies.
Authenticate:
- To sync Ansible collections from Private Automation Hub, enter your token in the Auth Token field.
-
To sync Ansible collections from
console.redhat.com, enter your token in the Auth Token field and enter your SSO URL in the Auth URL field. - To sync Ansible collections from Satellite, leave both authentication fields blank.
- Click Save.
- Navigate to the Ansible Collections repository.
- From the Select Action menu, select Sync Now.
Additional resources
1.7. Consuming content from an Ansible Collection repository Copy linkLink copied to clipboard!
Your hosts can consume content from an Ansible Collection repository on Satellite Server or Capsule Server. Configure the Ansible Galaxy client to use your Satellite Server or Capsule Server as a Galaxy server.
Prerequisites
- You have synchronized an Ansible Collection to a Satellite repository.
-
The
ansible-corepackage is installed on the host. This package is available in AppStream repositories.
Procedure
On the host, configure the
ansible-galaxyclient to use Satellite Server or Capsule Server as the Galaxy server. Add the required sections to anansible.cfgfile, for example:[galaxy] server_list = My_Library_Server, My_Promoted_CV_Server [galaxy_server.My_Library_Server] url = https://server.example.com/pulp_ansible/galaxy/My_Organization_Label/Library/custom/My_Product_Label/My_Repository_Label/api/ [galaxy_server.My_Promoted_CV_Server] url = https://server.example.com/pulp_ansible/galaxy/My_Organization_Label/My_Lifecycle_Environment_Label/My_Content_View_Label/custom/My_Product_Label/My_Repository_Label/api/Replace
server.example.comwith the fully qualified domain name of your Satellite Server or Capsule Server.Install an Ansible Collection from your Galaxy server. For example:
# ansible-galaxy collection install My_Namespace.My_Collection \ --server My_Library_Server
1.8. Customizing Ansible configuration Copy linkLink copied to clipboard!
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.
| 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
1.9. Using Ansible Vault with Satellite Copy linkLink copied to clipboard!
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_passwordAdd 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_passwordThe path to the Vault password file must be absolute.