011 Display variables iocage_*

Extending example 010 Clone basejails and create inventory.

Use case

Display all variables iocage_* created by the inventory plugin vbotka.freebsd.iocage.

Tree

shell> tree .
.
├── ansible.cfg
├── iocage.yml
└── pb-vars-all.yml

Synopsis

In a selected jail, display all variables iocage_* created by the inventory plugin in 010 Clone basejails and create inventory.

Requirements

ansible.cfg

[defaults]
gathering = explicit
callback_result_format = yaml

[connection]
pipelining = true

Inventory iocage.yml

plugin: vbotka.freebsd.iocage
host: 10.1.0.29
user: admin
compose:
  ansible_host: iocage_ip4
  release: iocage_release | split('-') | first
  release_major: iocage_release | split('-') | first | split('.') | first
  release_minor: iocage_release | split('-') | first | split('.') | last
groups:
    test: inventory_hostname.startswith('test')
keyed_groups:
  - prefix: distro
    key: iocage_release
  - prefix: state
    key: iocage_state

Playbook pb-vars-all.yml

- hosts: all

  tasks:

    - debug:
        msg: |
          inventory_hostname: {{ inventory_hostname }}
          ansible_host: {{ ansible_host }}

          {% for var in q('varnames', 'iocage_*') %}
          {{ var }}: {{ lookup('vars', var) }}
          {% endfor %}

Playbook output - Display iocage_* vars

(env) > ansible-playbook pb-vars-all.yml -i iocage.yml -l test_133
PLAY [all] *********************************************************************

TASK [debug] *******************************************************************
ok: [test_133] => 
    msg: |-
        inventory_hostname: test_133
        ansible_host: 10.1.0.133

        iocage_jid: 45
        iocage_boot: off
        iocage_state: up
        iocage_type: jail
        iocage_release: 15.0-RELEASE-p3
        iocage_ip4_dict: {'ip4': [{'ifc': 'vnet0', 'ip': '10.1.0.133', 'mask': '24'}], 'msg': ''}
        iocage_ip4: 10.1.0.133
        iocage_ip6: -
        iocage_template: ansible_client
        iocage_basejail: yes

PLAY RECAP *********************************************************************
test_133                   : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0