22.4. Managing repositories by using the rhc RHEL system role
Enabling repositories on a RHEL system is essential for accessing, installing, and updating software packages from verified sources. You can remotely enable or disable repositories on managed nodes by using rhc RHEL system role to ensure the system security, stability, and compatibility.
Prerequisites
- You have prepared the control node and the managed nodes.
- You are logged in to the control node as a user who can run playbooks on the managed nodes.
-
The account you use to connect to the managed nodes has
sudopermissions for these nodes. - You have details of the repositories which you want to enable or disable on the managed nodes.
- You have registered the system.
Procedure
Create a playbook file, for example,
~/playbook.yml, with the following content:--- - name: Managing systems with the rhc RHEL system role hosts: managed-node-01.example.com tasks: - name: Enable repository ansible.builtin.include_role: name: redhat.rhel_system_roles.rhc vars: rhc_repositories: - name: "RepositoryName" state: enabledThe settings specified in the example playbook include the following:
name: RepositoryName- Name of the repository that should be enabled.
state: enabled|disabled-
Optional, enables or disables the repository. Default is
enabled.
For details about all variables used in the playbook, see the
/usr/share/ansible/roles/rhel-system-roles.rhc/README.mdfile on the control node.Validate the playbook syntax:
$ ansible-playbook --syntax-check ~/playbook.ymlNote that this command only validates the syntax and does not protect against a wrong but valid configuration.
Run the playbook:
$ ansible-playbook ~/playbook.yml