Setup Ansible Control Node

Setup an Ansible Control Node based on Red Hat 8 on gsd-ansible.

This tutorial provides step-by-step instructions for setting up an Ansible Control Node  on Red Hat 8, specifically on the gsd-ansible node. While primarily intended for Ansible Ad-Hoc tasks, this control node can also serve as a graphical user interface (GUI) for lightweight development work, accessible via RDP (Remote Desktop Protocol). By following these guidelines, you’ll be able to create a versatile control node environment that supports both quick automation tasks and convenient development capabilities.


Overview

The diagram below illustrates the default provisioning process in the development environment using Vagrant and Ansible. The following VMs are created: gsd-ansible, gsd-agserver1 and gsd-rproxy1.

The Ansible Control Node, gsd-ansible, can be used separately to provision and manage the nodes using Ansible without relying on Vagrant.

These diagrams demonstrate the two provisioning approaches: one using Vagrant and Ansible together, and the other using Ansible independently with the Ansible Control Node.

Prerequisites

Create and register

vagrant up gsd-ansible --no-provision
vagrant ssh gsd-ansible
sudo su -
subscription-manager register --username <username>
subscription-manager attach
Show me
[vagrant@gsd-ansible ~]$ sudo su -
[root@gsd-ansible ~]# subscription-manager register --username <username>
Registering to: subscription.rhsm.redhat.com:443/subscription
Password:
The system has been registered with ID: 50b7543c-8e3d-4a80-801f-*******
The registered system name is: gsd-ansible

WARNING

The yum/dnf plugins: /etc/dnf/plugins/subscription-manager.conf were automatically enabled for the benefit of Red Hat Subscription Management. If not desired, use "subscription-manager config --rhsm.auto_enable_yum_plugins=0" to block this behavior.

[root@gsd-ansible ~]#

Snapshot

To avoid the need for manual node registration, you can simplify the process by creating a snapshot. Please note that using the vagrant destroy command will result in the deletion of all snapshots.

To create a snapshot, use the following command:

vagrant snapshot save gsd-ansible v0

To restore the snapshot, execute the following command:

vagrant snapshot restore gsd-ansible v0

By utilizing snapshots, you can efficiently manage your node configuration without the hassle of repetitive manual registration. Just remember to exercise caution when working with the vagrant destroy command to prevent unintended deletion of snapshots.

Provision

To provision the gsd-ansible node, run the following command:

vagrant provision gsd-ansible

The provisioning process for this node is determined by the contents of the group_vars/ansible/main.yml file, which utilizes the bootstrap_packages list, as well as the plays/mgmt/ansible.yml play. You can find the files in the Ansible project c2platform/rws/ansible-gis.

Here is an example of the bootstrap_packages configuration:

bootstrap_packages:
  - name: python3-pip
    type: os
  - name: upgrade pip and setuptools
    cmd: pip3 install --upgrade pip setuptools
    type: cmd
    changed_when: Successfully installed
  - name:
      - xrdp
      - virtualenv
      - "@Server with GUI"
    type: os

RDP

You can now create a RDP connection to this node using for example Remmina  . You should be able to connect using user vagrant with password vagrant.

Ansible environment

Each engineer must follow the instructions outlined in this section to set up their own personalized Ansible workspace.

Install pyenv  :

curl https://pyenv.run | bash

Add the following lines to ~/.bashrc:

export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

Install Python 3.10.6

source ~/.bashrc
pyenv install 3.10.6
pyenv global 3.10.6

Create Python virtual environment using penv virtualenv:

pyenv virtualenv rws
pyenv virtualenvs  # this will output all virtual environments available including "rws"
pyenv virtualenv-init rws
pyenv activate rws

In ~/.bashrc add

eval "$(pyenv virtualenv-init -)"
pyenv activate rws

Install Ansible

Install Ansible, including PIP packages for Kerberos and WinRM.

pip3 install -r requirements.txt  # ansible creates this file in vagrant home

Alternatively, you can run the following commands:

pip3 install --upgrade pip
pip3 install ansible-core==2.11.12
pip3 install setuptools_rust
pip3 install yamllint==1.28.0 ansible-lint==6.8.6 pre-commit==2.20.0
pip3 install pywinrm==0.4.3
pip3 install requests-kerberos
pip3 install pywinrm[kerberos] requests-kerberos pykerberos

Provision with Ansible

Once you have set up your Ansible environment, you can proceed with various tasks such as cloning the c2platform/rws/ansible-gis project, downloading Ansible collections, and provisioning nodes using Ansible.

To ensure that your environment is functional, the easiest way however is to utilize the /vagrant mount. This mount contains the c2platform/rws/ansible-gis project from your host. The only missing component is the ansible-dev-collections folder.

To incorporate this folder into gsd-ansible, you can create a special local and hidden file called .sync_folders.yml with the following contents. This file is in the git ignore list:

---
- src: ../ansible-dev-collections/
  target: /ansible-dev-collections

Once you reload, you should be able to provision the gsd environment as follows:

vagrant reload gsd-ansible  # will create /ansible-dev-collections mount
vagrant ssh gsd-ansible
cd /vagrant
ansible-playbook plays/gis/server.yml -i hosts.ini

Please note that the above provision assumes that you have the gsd-agserver1 already up and running.

With the Ansible Control Node, gsd-ansible, you can now manage the nodes using Ansible alone. Vagrant is no longer involved in the process.

See Vagrant Sync folders for more information about the .sync_folders.yml file.