Manage Red Hat Satellite by using the REST API and Ansible Playbooks for common tasks.
Outcomes
Create Satellite objects with curl REST API commands.
Create and manage Satellite objects by using playbooks from the Satellite Ansible Collection.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start api-review
Instructions
View the Finance organization ID by using the curl command with the REST API.
On workstation, view the Finance organization ID by using the REST API.
Format the command output for readability by using the python json.tool.
[student@workstation ~]$curl --request GET --insecure \ --user admin:redhat \ https://satellite.lab.example.com/katello/api/organizations \ | python3 -m json.tool...output omitted... "label": "Finance", "created_at": "2022-12-06 15:17:22 UTC", "updated_at": "2022-12-06 16:02:46 UTC","id": 7,"name": "Finance",...output omitted...
Create a lifecycle path with two additional lifecycle environments, Development and Testing, in the Finance organization.
The Development lifecycle follows the Library lifecycle environment, and the Testing lifecycle environment follows the Development lifecycle environment.
Verify the ID for the Library environment in the Finance organization.
Use the Finance organization ID from the previous command output.
[student@workstation ~]$curl --request GET --insecure \ --user admin:redhat \ https://satellite.lab.example.com/katello/api/organizations/...output omitted...7/environments \ | python3 -m json.tool"id": 4,"name": "Library","label": "Library", "description": null, "organization_id": 7, ...output omitted...
Create the ~/create-finance-lifecycle.json data file with parameters for the Development lifecycle environment.
Use the Finance organization ID from the previous command output.
Use the Library environment ID for the prior environment ID value.
[student@workstation ~]$cat /home/student/create-finance-lifecycle.json{"organization_id":7,"label":"development","name":"Development","prior":4}
Create the Development lifecycle environment by using a POST request.
[student@workstation ~]$ curl --header "Content-Type:application/json" \
--request POST --insecure --user admin:redhat \
--data @create-finance-lifecycle.json \
https://satellite.lab.example.com/katello/api/environments \
| python3 -m json.tool
...output omitted...
"id": 11,
"name": "Development",
"label": "development",
"description": null,
"organization_id": 7,
"organization": {
"name": "Finance",
"label": "Finance",
"id": 7
},
"created_at": "2022-12-06 17:44:30 UTC",
"updated_at": "2022-12-06 17:44:30 UTC",
"prior": {
"name": "Library",
"id": 4
...output omitted...Modify the ~/create-finance-lifecycle.json data file with parameters for the Testing lifecycle environment.
Use the Finance organization ID from the previous command output.
Use the Development environment ID for the prior environment ID value.
[student@workstation ~]$cat /home/student/create-finance-lifecycle.json{"organization_id":7,"label":"testing","name":"Testing","prior":11}
Create the Testing lifecycle environment by using a POST request.
[student@workstation ~]$ curl --header "Content-Type:application/json" \
--request POST --insecure --user admin:redhat \
--data @create-finance-lifecycle.json \
https://satellite.lab.example.com/katello/api/environments \
| python3 -m json.tool
...output omitted...
"id": 12,
"name": "Testing",
"label": "testing",
"description": null,
"organization_id": 7,
"organization": {
"name": "Finance",
"label": "Finance",
"id": 7
},
"created_at": "2022-12-06 17:46:01 UTC",
"updated_at": "2022-12-06 17:46:01 UTC",
"prior": {
"name": "Development",
"id": 11
...output omitted...Verify that the created environment path is in the Finance organization.
[student@finance ~]$ curl --request GET --insecure \
--user admin:redhat \
https://satellite.lab.example.com/katello/api/organizations/6/environments \
| python3 -m json.tool
...output omitted...
"id": 11,
"name": "Development",
"label": "development",
"description": null,
"organization_id": 7,
"organization": {
"name": "Finance",
"label": "Finance",
"id": 7
},
"created_at": "2022-12-06 17:54:30 UTC",
"updated_at": "2022-12-06 17:54:30 UTC",
"prior": {
"name": "Library",
"id": 4
},
"successor": {
"name": "Testing",
"id": 12
},
...output omitted...Prepare to use Satellite Ansible Collection to perform Satellite management tasks.
Install the Satellite Ansible Collection and the community.general Ansible Galaxy collection to the default system-shared location.
Create a sat_vars.yml variable file in an ansible-lab working subdirectory.
Access the Satellite web UI at the https://satellite.lab.example.com URL, by using the admin user with redhat as the password.
Verify that the installed Ansible is version 2.9 or later.
[student@workstation ~]$ ansible --version
ansible [core 2.12.2]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/student/.ansible/plugins/modules',
'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.9/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.10 (main, Feb 9, 2022, 00:00:00) [GCC 11.2.1 20220127
(Red Hat 11.2.1-9)]
jinja version = 2.11.3
libyaml = TrueInstall the Satellite Ansible Collection and the community.general collection to the common system location for shared Ansible components.
[student@workstation ~]$sudo ansible-galaxy collection install \ -p /usr/share/ansible/collections/ redhat-satellite-3.6.0.tgz[sudo] password for student:student...output omitted... [student@workstation ~]$sudo ansible-galaxy collection install \ -p /usr/share/ansible/collections/ community-general-7.2.1.tar.gz[sudo] password for student:student...output omitted...
Create the ansible-lab working directory to store your Ansible files.
The directory might already exist.
[student@workstation ~]$mkdir ansible-lab[student@workstation ~]$cd ansible-lab[student@workstation ansible-lab]$
Create the sat_vars.yml variable file for Satellite Server access parameters.
Use the following content and values.
[student@workstation ansible-lab]$cat sat_vars.yml--- sat_url: https://satellite.lab.example.com sat_un: admin sat_pw: redhat cert_validate: no
Create the activation-key.yml playbook.
Run the playbook to create a FinancePlaybook activation key in the Finance organization.
Use the FinanceServerBase content view and the Build lifecycle.
If necessary, read the activation_key module documentation.
Read the module documentation to discover the required module parameters and to view example playbook syntax. Use the module's fully qualified name.
[student@workstation ansible-lab]$ ansible-doc redhat.satellite.activation_key
...output omitted...Create the activation-key.yml playbook with the following content.
[student@workstation ansible-lab]$ cat activation-key.yml
- hosts: localhost
vars_files:
- sat_vars.yml
vars:
activation_key: FinancePlaybook
lifecycle_env: Build
content_view: FinanceServerBase
organization: Finance
tasks:
- name: Create the {{ activation_key }}Activation Key
redhat.satellite.activation_key:
name: "{{ activation_key }}"
lifecycle_environment: "{{ lifecycle_env }}"
content_view: "{{ content_view }}"
organization: "{{ organization }}"
state: present
server_url: "{{ sat_url }}"
username: "{{ sat_un }}"
password: "{{ sat_pw }}"
validate_certs: "{{ cert_validate }}"Run the playbook to create the activation key.
[student@workstation ansible-lab]$ ansible-playbook activation-key.yml
...output omitted...Review the newly created FinancePlaybook activation key in the Finance organization by using the REST API.
[student@workstation ansible-lab]$ curl --request GET --insecure \
--user admin:redhat \
https://satellite.lab.example.com/katello/api/organizations/7/activation_keys \
| python3 -m json.tool
...output omitted...
"id": 1,
"name": "FinancePlaybook",
"description": null,
"unlimited_hosts": true,
"auto_attach": true,
"content_view_id": 5,
"environment_id": 5,
...output omitted...Create the register-host.yml playbook.
Run the playbook to register the serverd system in the Finance organization with the FinanceServers activation key.
Use the redhat_subscription module, which is part of the community.general Ansible Galaxy collection.
The Finance organization enables Simple Content Access.
Read the module documentation to discover the required module parameters and to view example playbook syntax.
[student@workstation ansible-lab]$ ansible-doc redhat_subscription
...output omitted...Create an inventory file that contains the serverd system to register.
[student@workstation ansible-lab]$ cat inventory
serverdCreate the register-host.yml playbook with the following content.
[student@workstation ansible-lab]$ cat register-host.yml
- hosts: serverd
vars_files:
- sat_vars.yml
vars:
activation_key: FinancePlaybook
lifecycle_env: Build
Organization_Name: Finance
tasks:
- name: Prepare System for Satellite Registration - Get Cert
get_url:
url: "{{ sat_url }}/pub/katello-ca-consumer-latest.noarch.rpm"
dest: /tmp/katello-latest.rpm
validate_certs: no
- name: Install Katello rpm
yum:
name: /tmp/katello-latest.rpm
state: latest
disable_gpg_check: yes
become: yes
- name: Register with Activation key
redhat_subscription:
state: present
activationkey: "{{ activation_key }}"
org_id: "{{ Organization_Name }}"
become: yesRun the playbook to create the activation key.
Use the -K option to request that you are prompted to provide the become password.
[student@workstation ansible-lab]$ansible-playbook -i inventory \ register-host.yml -KBECOME password:student...output omitted...
Review the serverd host registration by using the REST API.
Use the Finance organization ID from the previous command output.
[student@workstation ~]$ curl --request GET --insecure \
--user admin:redhat \
https://satellite.lab.example.com/api/organizations/7/hosts \
| python3 -m json.tool
...output omitted...
"name": "serverd.lab.example.com",
"id": 2,
"puppet_proxy_id": null,
"puppet_proxy_name": null,
"puppet_ca_proxy_id": null,
"puppet_ca_proxy_name": null,
"openscap_proxy_id": null,
"openscap_proxy_name": null,Return to the student home directory.
[student@workstation ansible-lab]$ cd
[student@workstation ~]$