Chapter 5. Automating Satellite management with Satellite Ansible Collection
Satellite Ansible Collection is a set of Ansible modules that interact with the Satellite API. You can use these modules to automate many aspects of Satellite administration.
5.1. Installing the Satellite Ansible modules Copy linkLink copied to clipboard!
Modules from the Satellite Ansible Collection are provided by the ansible-collection-redhat-satellite
package. On your Satellite Server, the package is installed by default. If you want to execute your playbooks on a different system, you must first install the package that provides them.
You can execute your playbooks on any system that can reach the Satellite API. This can also be your Satellite Server itself.
Procedure
Install the
ansible-collection-redhat-satellite
package:dnf install ansible-collection-redhat-satellite
# dnf install ansible-collection-redhat-satellite
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Display the list of Ansible modules that are now available on your system:
ansible-doc --list redhat.satellite
# ansible-doc --list redhat.satellite
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Next steps
- You can now use the installed Ansible modules to execute playbooks.
5.2. Creating a playbook with modules from Satellite Ansible Collection Copy linkLink copied to clipboard!
Ansible modules from the Satellite Ansible Collection must be able to communicate with the Satellite API over HTTPS. In your playbooks, include parameters specifying how to authenticate to enable the connection to API.
Do not store sensitive credentials, such as username and password, directly in your playbooks or environment variables. The following examples use Ansible vault to manage sensitive data.
Prerequisites
- A user account in Satellite exists with permissions to perform the action defined in your playbook.
You have access to one of the following types of authentication credentials for that user:
- Username and password
- Username and Personal Access Token
A system that you will execute your playbook against. The following examples use
localhost
.This system must be able to reach the Satellite API. You can choose from these options:
- A system that can reach the Satellite API directly. You can use your Satellite Server, your Capsule Servers, or any other system in your environment.
- A system without a direct connection to the Satellite API that uses an HTTP proxy to connect to Satellite.
Procedure
Store your sensitive variables in an encrypted file:
Create an Ansible vault. For example, to create a vault named My_Vault.yml:
ansible-vault create My_Vault.yml
$ ansible-vault create My_Vault.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow After the
ansible-vault create
command opens an editor, provide the required parameters in the key: value format.If you want to authenticate with Satellite username and password:
My_Username: My_Admin_User_Account My_Password: My_Admin_Password My_Server_URL: https://satellite.example.com
My_Username: My_Admin_User_Account My_Password: My_Admin_Password My_Server_URL: https://satellite.example.com
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you want to authenticate with Satellite username and Personal Access Token (PAT):
My_Username: My_Admin_User_Account My_Password: My_PAT My_Server_URL: https://satellite.example.com
My_Username: My_Admin_User_Account My_Password: My_PAT My_Server_URL: https://satellite.example.com
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you use an HTTP proxy to reach the Satellite API, store it in the vault too:
My_HTTP_Proxy: "http://proxy.example.com:8080"
My_HTTP_Proxy: "http://proxy.example.com:8080"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Save your changes and close the editor. Ansible encrypts the data in the vault.
Create a playbook file that references the vault file:
NoteThe following YAML snippets include the
module_defaults
keyword to pass vault variables as parameters to all modules from the redhat.satellite.satellite group that are used in the playbook. Module defaults groups simplify parameter management by enabling you to define common parameters to groups of modules rather than having to pass the parameters to each module individually.Provide details on how to authenticate to the Satellite API.
If you are authenticating with Satellite username and password or PAT, map the
username
,password
, andserver_url
parameters to the contents of My_Vault.yml:Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you need to use an HTTP proxy to reach the Satellite API, set the
https_proxy
environment variable:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
In the
tasks:
section, define the tasks that you want your playbook to perform.
Validate the playbook syntax:
ansible-playbook --syntax-check --ask-vault-pass My_Playbook.yml
$ ansible-playbook --syntax-check --ask-vault-pass My_Playbook.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note that this command only validates the syntax. It does not protect against a valid but incorrect configuration.
Run the playbook:
ansible-playbook --ask-vault-pass My_Playbook.yml
$ ansible-playbook --ask-vault-pass My_Playbook.yml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Example 5.1. Example Ansible playbook: Ensure that domain new.example.com
exists in Satellite
The redhat.satellite.domain
module can create, update, and delete domains. This example playbook uses redhat.satellite.domain
to ensure that a domain named new.example.com
exists and is managed by Satellite. For additional examples, see Section 5.3, “Example playbooks based on modules from Satellite Ansible Collection”.
The settings specified in the example playbook include the following:
vars_files
-
The name of the vault file that stores the variables
My_Username
,My_Password
, andMy_Server_URL
. module_defaults
-
The module defaults group that maps the variables from the vault file to the
username
,password
, andserver_url
module parameters. name
- The name of the domain that you want to ensure exists in Satellite.
For more information, see the Ansible module documentation with ansible-doc redhat.satellite.domain
.
Additional resources
- For information about using Ansible vault, see Protecting sensitive data with Ansible vault in Ansible Community Documentation.
- For information about using module defaults, see Module defaults in Ansible Community Documentation.
5.3. Example playbooks based on modules from Satellite Ansible Collection Copy linkLink copied to clipboard!
All playbooks based on modules from Satellite Ansible Collection must include parameters detailing how to connect to the Satellite API. The following examples use Ansible vault and module defaults group to provide these parameters, and they authenticate using a username and password. For more information, see Section 5.2, “Creating a playbook with modules from Satellite Ansible Collection”.
Example 5.2. Example Ansible playbook: Enable repositories and create a content view
This example playbook uses the following modules:
-
redhat.satellite.repository_set
-
redhat.satellite.content_view
The playbook ensures repositories are enabled and a content view that contains these repositories exists.
Before you run this playbook, ensure that you have uploaded a manifest and can access the Red Hat CDN.
For more information, see the Ansible module documentation with the following commands:
-
ansible-doc redhat.satellite.repository_sync
-
ansible-doc redhat.satellite.content_view
Example 5.3. Example Ansible playbook: Synchronize repositories and publish a content view
This example playbook uses the following modules:
-
redhat.satellite.repository_sync
-
redhat.satellite.content_view_version
The playbook synchronizes repositories and publishes the content view that includes them.
Before you run this playbook, ensure that you have enabled the required repositories and created a content view. For an example playbook that ensures this, see Example 5.2, “Example Ansible playbook: Enable repositories and create a content view”.
For more information, see the Ansible module documentation with the following commands:
-
ansible-doc redhat.satellite.repository_sync
-
ansible-doc redhat.satellite.content_view_version
Additional resources
-
Use the
ansible-doc --list redhat.satellite
command to display the Satellite Ansible modules installed on your system. - See Red Hat Ansible Automation Platform for a complete list of Satellite Ansible modules and other related information.