Skip to content

Add virt_who role to deploy and configure virt-who#203

Open
chris1984 wants to merge 1 commit into
theforeman:developfrom
chris1984:add-virtwho
Open

Add virt_who role to deploy and configure virt-who#203
chris1984 wants to merge 1 commit into
theforeman:developfrom
chris1984:add-virtwho

Conversation

@chris1984

@chris1984 chris1984 commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds a new virt_who role that converts the bash deployment script from the foreman_virt_who_configure plugin into an idempotent Ansible role
  • Supports all hypervisor types: ESX, Hyper-V, libvirt, KubeVirt, and AHV
  • Handles package installation with satellite-maintain/foreman-maintain package locking awareness, credential encryption via virt-who-password, config file templating, and service management
  • Related Jira

Motivation

The foreman_virt_who_configure plugin currently generates a bash script that users must manually download, copy to the target host, and execute. This has no idempotency, no error recovery, and no integration with existing configuration management workflows. An Ansible role enables direct deployment via Foreman Remote Execution (REX) and fits into existing automation pipelines.

Role details

Tasks:

  1. Validate required variables (with non-empty checks to prevent hangs on virt-who-password)
  2. Install virt-who — detects satellite-maintain / foreman-maintain for package locking, falls back to standard package manager
  3. Verify minimum virt-who version (>= 0.24.2)
  4. Encrypt hypervisor and service user passwords on the target host using virt-who-password
  5. Template per-config file to /etc/virt-who.d/.conf
  6. Template global config to /etc/virt-who.conf
  7. Enable service; restart via handler only when config files change

Features:

  • Host filtering (whitelist/blacklist) with parent compute resource support
  • HTTP/HTTPS proxy and no_proxy configuration
  • AHV-specific options (Prism Central/Element, internal debug)
  • KubeVirt kubeconfig support
  • Multiple configs can be deployed to the same host with different identifiers
  • Passwords handled with no_log: true

Test plan

  • molecule/default/ — deploys 6 configs covering all hypervisor types, whitelist/blacklist filtering, and proxy settings; verifies config file content and service state
  • molecule/validation/ — verifies assertion failures for missing required vars, empty passwords, invalid hypervisor type, and missing kubeconfig
  • Manual end-to-end test against a subscribed host with virt-who available

Manual tested on a VM checked out with broker and deployed 3 configs with three different organizations and all reported correctly, virt-who got installed and started up correctly, rerunning the role was idempotent:

[vagrant@host foreman_virt_who_configure]$ cd ../foreman-operations-collection/
[vagrant@host foreman-operations-collection]$ ANSIBLE_ROLES_PATH=/home/vagrant/foreman-operations-collection/roles ansible-playbook -i 10.0.0.0, test_virtwho.yml -k -u root
SSH password:

PLAY [all] ******************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************************************
ok: [10.0.0.0]

TASK [virt_who : Check that required variables are defined] *****************************************************************************************************************************************************
ok: [10.0.0.0] => {
    "changed": false,
    "msg": "All assertions passed"
}

TASK [virt_who : Check that hypervisor server and username are defined] *****************************************************************************************************************************************
ok: [10.0.0.0] => {
    "changed": false,
    "msg": "All assertions passed"
}

TASK [virt_who : Check that hypervisor password is defined] *****************************************************************************************************************************************************
ok: [10.0.0.0] => {
    "changed": false,
    "msg": "All assertions passed"
}

TASK [virt_who : Check that kubeconfig path is defined for kubevirt] ********************************************************************************************************************************************
skipping: [10.0.0.0]

TASK [virt_who : Check if virt-who is already installed] ********************************************************************************************************************************************************
ok: [10.0.0.0]

TASK [virt_who : Check for satellite-maintain] ******************************************************************************************************************************************************************
skipping: [10.0.0.0]

TASK [virt_who : Check for foreman-maintain] ********************************************************************************************************************************************************************
skipping: [10.0.0.0]

TASK [virt_who : Unlock packages via satellite-maintain] ********************************************************************************************************************************************************
skipping: [10.0.0.0]

TASK [virt_who : Install virt-who via satellite-maintain] *******************************************************************************************************************************************************
skipping: [10.0.0.0]

TASK [virt_who : Lock packages via satellite-maintain] **********************************************************************************************************************************************************
skipping: [10.0.0.0]

TASK [virt_who : Unlock packages via foreman-maintain] **********************************************************************************************************************************************************
skipping: [10.0.0.0]

TASK [virt_who : Install virt-who via foreman-maintain] *********************************************************************************************************************************************************
skipping: [10.0.0.0]

TASK [virt_who : Lock packages via foreman-maintain] ************************************************************************************************************************************************************
skipping: [10.0.0.0]

TASK [virt_who : Install virt-who via package manager] **********************************************************************************************************************************************************
skipping: [10.0.0.0]

TASK [virt_who : Get installed virt-who version] ****************************************************************************************************************************************************************
ok: [10.0.0.0]

TASK [virt_who : Verify minimum virt-who version] ***************************************************************************************************************************************************************
ok: [10.0.0.0] => {
    "changed": false,
    "msg": "All assertions passed"
}

TASK [virt_who : Encrypt hypervisor password] *******************************************************************************************************************************************************************
ok: [10.0.0.0]

TASK [virt_who : Encrypt service user password] *****************************************************************************************************************************************************************
ok: [10.0.0.0]

TASK [virt_who : Set encrypted password facts] ******************************************************************************************************************************************************************
ok: [10.0.0.0]

TASK [virt_who : Ensure virt-who config directory exists] *******************************************************************************************************************************************************
ok: [10.0.0.0]

TASK [virt_who : Deploy virt-who per-config configuration] ******************************************************************************************************************************************************
ok: [10.0.0.0]

TASK [virt_who : Deploy virt-who global configuration] **********************************************************************************************************************************************************
ok: [10.0.0.0]

TASK [virt_who : Enable virt-who service] ***********************************************************************************************************************************************************************
ok: [10.0.0.0]

PLAY RECAP ******************************************************************************************************************************************************************************************************
10.0.0.0               : ok=14   changed=0    unreachable=0    failed=0    skipped=10   rescued=0    ignored=0

Converts the bash deployment script from the foreman_virt_who_configure
plugin into an idempotent Ansible role. The role handles package
installation (with satellite-maintain/foreman-maintain awareness),
credential encryption, config file templating, and service management
for all supported hypervisor types (esx, hyperv, libvirt, kubevirt, ahv).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant