Search

Chapter 1. Getting started with Ansible in Satellite

download PDF

Use this guide to configure Satellite to use Ansible for remote execution.

1.1. Supported Ansible versions

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 OS configuration.

1.2. Configuring your Satellite to run Ansible roles

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

  1. 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.
  2. 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
  3. Distribute SSH keys to enable Capsules to connect to hosts using SSH. For more information, see Distributing SSH Keys for Remote Execution in Managing hosts. Satellite runs Ansible roles the same way it runs remote execution jobs.
  4. Import the Ansible roles into Satellite.
  5. Proceed to Chapter 2, Using Ansible roles to automate repetitive tasks on clients.

1.3. Enabling Ansible integration with Satellite

Perform the following procedure to enable the Ansible plugin on your Satellite Server.

Procedure

  • Enable the Ansible plugin on your Satellite Server:

    # satellite-installer \
    --enable-foreman-plugin-ansible \
    --enable-foreman-proxy-plugin-ansible

1.4. Importing Ansible roles and variables

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

  1. In the Satellite web UI, navigate to Configure > Ansible > Roles.
  2. Click Import to select the Capsule from which you want to import.
  3. Select the roles that you want to import.
  4. Click Submit.

1.5. Overriding Ansible variables in Satellite

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

Procedure

  1. In the Satellite web UI, navigate to Configure > Ansible > Variables.
  2. Select the Ansible variable that you want to override and manage with Satellite.
  3. In the Default Behavior area, select the Override checkbox.
  4. 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.
  5. In the Default Value field, enter the default value that you want to use if there is no match for the variable.
  6. 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.
  7. 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.
  8. 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, environment would expect matchers such as hostgroup = "web servers" AND environment = 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.
  9. Optional: Expand the Specify Matchers area and specify criteria for selecting hosts on which the variable overrides.
  10. 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

  1. In the Satellite web UI, navigate to Hosts > All Hosts and select the host that you want to use.
  2. Click the Ansible tab, and in the Variables area, click the pencil icon to edit the value of the variable.
  3. 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

  1. In the Satellite web UI, navigate to Configure > Host Groups, and select the host group that you want to use.
  2. Click the Parameters tab, and in the Host Group Parameters area, click Add Parameter.
  3. In the Name field, add the Ansible variable name.
  4. From the Type list, select the type of the variable for validation.
  5. In the Value field, enter the value for the variable.

Adding the variable as a global parameter

  1. In the Satellite web UI, navigate to Configure > Global Parameters, and click Create Parameter.
  2. In the Name field, add the Ansible variable name.
  3. From the Type list, select the type of the variable for validation.
  4. In the Value field, enter the value for the variable.
  5. 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.6. 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. 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 channels, see the Red Hat Enterprise Linux Extras Product Lifecycle article.

Procedure

  1. Ensure that the following repository is enabled:

    • On Red Hat Enterprise Linux 8, ensure that the Appstream repository is enabled:

      # 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
  2. Install the rhel-system-roles package:

    # satellite-maintain packages install rhel-system-roles

    The rhel-system-roles package downloads to /usr/share/ansible/roles/. You can view and make any modifications that you want to the files before you import.

  3. In the Satellite web UI, navigate to Configure > Ansible > Roles.
  4. Click the Capsule that contains the roles that you want to import.
  5. 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.7. Synchronizing Ansible Collections

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.

Procedure

  1. In the Satellite web UI, navigate to Content > Products.
  2. Select the required product name.
  3. In the Products window, select the name of a product that you want to create a repository for.
  4. Click the Repositories tab, and then click New Repository.
  5. In the Name field, enter a name for the repository.

    The Label field is populated automatically based on the name.

  6. From the Type list, select ansible collection.
  7. 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/.

  8. 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.3

    For more information, see Installing roles and collections from the same requirements.yml file in the Galaxy User Guide.

  9. Authenticate.

    1. To sync Satellite from Private Automation Hub, enter your token in the Auth Token field.

      For more information, see Connect Private Automation Hub in Connect to Hub.

    2. To sync Satellite from console.redhat.com, enter your token in the Auth Token field and enter your SSO URL in the the Auth URL field.

      For more information, see Getting started with automation hub.

    3. To sync Satellite from Satellite, leave both authentication fields blank.
  10. Click Save.
  11. Navigate to the Ansible Collections repository.
  12. From the Select Action menu, select Sync Now.

1.8. 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 1.1. Essential Ansible configuration
Environment VariableConfig KeyDescription

ANSIBLE_CALLBACKS_ENABLED

callbacks_enabled

Enables callback to Satellite; equivalent to callback_whitelist for cross-version compatibility

ANSIBLE_CALLBACK_WHITELIST

callback_whitelist

Enables callback to Satellite; equivalent to callbacks_enabled for cross-version compatibility

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

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

  1. If you customized /etc/ansible/ansible.cfg, copy your configuration from /etc/ansible/ansible.cfg to /usr/share/foreman-proxy/.ansible.cfg.
  2. Encrypt the sensitive file using the ansible-vault command:

    # ansible-vault encrypt /etc/ansible/roles/Role_Name/vars/main.yml

    Note that ansible-vault changes the file permissions to 600.

  3. Change the group and permissions of the encrypted file to ensure that the foreman-proxy user can read it:

    # chgrp foreman-proxy /etc/ansible/roles/Role_Name/vars/main.yml
    # chmod 0640 /etc/ansible/roles/Role_Name/vars/main.yml
  4. Create the /usr/share/foreman-proxy/.ansible_vault_password file and enter the Vault password into it.
  5. Change the user and permissions of the .ansible_vault_password file to ensure that only the foreman-proxy user can read it:

    # chown foreman-proxy:foreman-proxy /usr/share/foreman-proxy/.ansible_vault_password
    # chmod 0400 /usr/share/foreman-proxy/.ansible_vault_password
  6. 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.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.