π₯οΈ Configuring an Ansible Control Node
The following steps describe how to configure an Ansible control node. These steps have been automated using the Ansible deployment playbook.
π½ Adding a Second Drive
- Add a new disk from the Proxmox web GUI.
- Boot the VM.
- Enumerate the new disk using
fdisk -l. - Use
fdiskto create a new partition. - Format the new partition (e.g.,
sudo mkfs -t ext4 /dev/vdb1). - Create the mount point
/ansible(e.g.,sudo mkdir /ansible). - Add the new mount point to
/etc/fstab(e.g.,
/dev/vdb1 /ansible ext4 defaults 0 2). - Mount the disk (e.g.,
sudo mount /ansible). - Grant full group access:
sudo chmod -R g+rwx /ansible.
π’ Joining the Machine to Active Directory
See the guide:
[Looks like the result wasn't safe to show. Let's switch things up and try something else!]
π Configure the Ansible Become User
Use a nonβroot user for privilege escalation. The Active Directory user ansible@refol.us will serve as the Ansible become user.
Create the Ansible Active Directory User
New-ADUser -Name "Ansible" -GivenName "Ansible" -Surname "User" -SamAccountName "ansible" -UserPrincipalName "ansible@refol.us" -AccountPassword(Read-Host -AsSecureString "Input Password") -Enabled $true
Enter a password when prompted.
Grant Proxmox Permissions to the ansible User
In Proxmox:
Datacenter β Permissions β Users β Add
Add the user ansible.
βIMPORTANT The Active Directory domain
refol.usmust be added as a Realm before adding the user.
Navigate to Datacenter β Permissions β Realms β Add β Active Directory Server.
Create a Proxmox API Token
This token will be used by Ansible for API calls.
Datacenter β Permissions β API Tokens β Add
- User:
ansible@refol.us - Token ID:
ansible_become_user
Click Add, then copy the Token ID and Secret.
Create the ansible Group
sudo addgroup ansible
Add ansible@refol.us to the ansible Group
sudo usermod -a -G ansible ansible@refol.us
sudo usermod -a -G ansible ansible
Add ansible@refol.us to the sudo Group
sudo usermod -a -G sudo ansible@refol.us
sudo usermod -a -G sudo ansible
Configure Ansible Become Settings
become: true
become_user: ansible
become_method: sudo
π¦ Ansible Installation
As of this writing, the latest version is Ansible 10.4.0, which includes ansible-core 2.17.4.
Install Python
sudo apt-get update
sudo apt-get install python3
Create a Python Virtual Environment
A virtual environment allows multiple Ansible versions to coexist.
Install the venv Module
sudo apt-get update
sudo apt-get install python3.12-venv
Create and Activate the Virtual Environment
cd /ansible
python3 -m venv python3.12.3_ansible10.4.0
source python3.12.3_ansible10.4.0/bin/activate
Deactivate with:
deactivate
Upgrade pip
pip install --upgrade pip setuptools
Install Ansible
pip install ansible
Verify installation:
ansible --version
(Version output omitted for brevity.)
π Install Python Modules
proxmoxer
python -m pip install proxmoxer
requests
python -m pip install requests
pycdlib
python -m pip install pycdlib
Other Required Packages
sudo apt install sshpass acl
π Getting Started with Ansible
Activate the Working Environment
cd /ansible/dev
source ../python3.12.3_ansible10.4.0/bin/activate
Create ansible.cfg
ansible-config init --disabled -t all > ansible.cfg
Configure the Vault Password File
Create ~/.vault_pass.txt and add your vault password.
In ansible.cfg:
vault_password_file=~/.vault_pass.txt
π Configure SSH Access to Proxmox Servers
Ensure the Ansible account can SSH into each Proxmox node:
ssh pve-0
ssh pve-1
ssh pve-2
Ensure the become user can also connect:
ssh ansible@pve-0
ssh ansible@pve-1
ssh ansible@pve-2
Test connectivity:
ansible pvenodes -i inventory/pve/inventory.ini -m ping --user=ansible -k
Enter the password when prompted.
π§Ή Ansible Lint
pip3 install ansible-lint
π References
- https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html
https://docs.ansible.com/ansible/latest/cli/ansible-config.html(docs.ansible.com in Bing)- https://docs.ansible.com/ansible/latest/reference_appendices/config.html
- https://ansible.readthedocs.io/projects/lint/installing/
- https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html