204 Create DHCP jails with auto UUID and iocage_tags v2

Extending example 203 Create DHCP jails with auto UUID and iocage_tags

Use case

Instead of the module vbotka.freebsd.iocage create the variable iocage_jails using the filter vbotka.freebsd.iocage

pb-iocage-ansible-clients-v2/iocage_jails.yml
---
- name: Get iocage list of jails
  register: out
  changed_when: false
  ansible.builtin.command: iocage list --long

- name: Set dictionary iocage_jails
  ansible.builtin.set_fact:
    iocage_jails: "{{ out.stdout | vbotka.freebsd.iocage('jails') }}"

- name: Get properties of iocage jails
  register: out
  changed_when: false
  ansible.builtin.command: "iocage get --all {{ item }}"
  loop: "{{ iocage_jails.keys() }}"

- name: Set dictionary iocage_jails_properties
  vars:
    _keys: "{{ out.results | map(attribute='item') }}"
    _vals: "{{ out.results | map(attribute='stdout_lines')
                           | map('map', 'split', ':', 1)
                           | map('community.general.dict')
                           | map('community.general.dict_kv', 'properties') }}"
  ansible.builtin.set_fact:
    iocage_jails_properties: "{{ dict(_keys | zip(_vals))  }}"

- name: Combine iocage_jails and iocage_jails_properties
  ansible.builtin.set_fact:
    iocage_jails: "{{ [iocage_jails, iocage_jails_properties] | combine(recursive=true) }}"

Test filter vbotka.freebsd.iocage

Given the input vars/iocage_datasets.yml

---

iocage_dict:
  jails: |
    +------+----------------+------+-------+------+-----------------+-------------------+-----+----------------+----------+
    | JID  |      NAME      | BOOT | STATE | TYPE |     RELEASE     |        IP4        | IP6 |    TEMPLATE    | BASEJAIL |
    +======+================+======+=======+======+=================+===================+=====+================+==========+
    | None | ansible_client | off  | down  | jail | 14.1-RELEASE-p6 | em0|10.1.0.199/24 | -   | -              | no       |
    +------+----------------+------+-------+------+-----------------+-------------------+-----+----------------+----------+
    | None | test_111       | off  | down  | jail | 14.1-RELEASE-p6 | em0|10.1.0.111/24 | -   | ansible_client | no       |
    +------+----------------+------+-------+------+-----------------+-------------------+-----+----------------+----------+
  releases: |
    14.1-RELEASE

iocage_jails: |
  +------+----------------+------+-------+------+-----------------+-------------------+-----+----------------+----------+
  | JID  |      NAME      | BOOT | STATE | TYPE |     RELEASE     |        IP4        | IP6 |    TEMPLATE    | BASEJAIL |
  +======+================+======+=======+======+=================+===================+=====+================+==========+
  | None | ansible_client | off  | down  | jail | 14.1-RELEASE-p6 | em0|10.1.0.199/24 | -   | -              | no       |
  +------+----------------+------+-------+------+-----------------+-------------------+-----+----------------+----------+
  | None | test_111       | off  | down  | jail | 14.1-RELEASE-p6 | em0|10.1.0.111/24 | -   | ansible_client | no       |
  +------+----------------+------+-------+------+-----------------+-------------------+-----+----------------+----------+

iocage_releases: |
  14.1-RELEASE

The below playbook pb-test-filter.yml

- name: Test filter vbotka.freebsd.iocage
  hosts: localhost

  vars_files:
    - iocage_datasets.yml

  vars:

    result: "{{ iocage_dict | vbotka.freebsd.iocage }}"
    jails: "{{ iocage_jails | vbotka.freebsd.iocage('jails') }}"
    releases: "{{ iocage_releases | vbotka.freebsd.iocage('releases') }}"

  tasks:

    - debug:
        var: result

    - debug:
        var: jails

    - debug:
        var: releases

gives

PLAY [Test filter vbotka.freebsd.iocage] ***************************************

TASK [debug] *******************************************************************
ok: [localhost] => 
    result:
        jails:
            ansible_client:
                basejail: 'no'
                boot: 'off'
                ip4: 10.1.0.199
                ip4_dict:
                    ip4:
                    -   ifc: em0
                        ip: 10.1.0.199
                        mask: '24'
                    msg: ''
                ip6: '-'
                jid: None
                release: 14.1-RELEASE-p6
                state: down
                template: '-'
                type: jail
            test_111:
                basejail: 'no'
                boot: 'off'
                ip4: 10.1.0.111
                ip4_dict:
                    ip4:
                    -   ifc: em0
                        ip: 10.1.0.111
                        mask: '24'
                    msg: ''
                ip6: '-'
                jid: None
                release: 14.1-RELEASE-p6
                state: down
                template: ansible_client
                type: jail
        releases:
        - 14.1-RELEASE

TASK [debug] *******************************************************************
ok: [localhost] => 
    jails:
        ansible_client:
            basejail: 'no'
            boot: 'off'
            ip4: 10.1.0.199
            ip4_dict:
                ip4:
                -   ifc: em0
                    ip: 10.1.0.199
                    mask: '24'
                msg: ''
            ip6: '-'
            jid: None
            release: 14.1-RELEASE-p6
            state: down
            template: '-'
            type: jail
        test_111:
            basejail: 'no'
            boot: 'off'
            ip4: 10.1.0.111
            ip4_dict:
                ip4:
                -   ifc: em0
                    ip: 10.1.0.111
                    mask: '24'
                msg: ''
            ip6: '-'
            jid: None
            release: 14.1-RELEASE-p6
            state: down
            template: ansible_client
            type: jail

TASK [debug] *******************************************************************
ok: [localhost] => 
    releases:
    - 14.1-RELEASE

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Tree

shell> tree .
.
├── ansible.cfg
├── group_vars
│   └── all
│       └── iocage.yml
├── hosts
│   ├── 02_iocage.yml
│   ├── 04_iocage.yml
│   └── 99_constructed.yml
├── iocage.ini
├── pb-iocage-ansible-clients-v2
│   ├── iocage_jails.yml
│   ├── swarm_destroy.yml
│   └── swarm.yml
├── pb-iocage-ansible-clients-v2.yml
├── pb-test.yml
├── pb-test-filter.yml
└── vars
    └── iocage_datasets.yml

Synopsis

  • At two managed nodes:

    • iocage_02

    • iocage_04

    In the playbook pb-iocage-ansible-clients-v2.yml, use:

    • module ansible.builtin.command to:

      • create variable iocage_jails

      • create jails

      • start jails

      • optionally, stop and destroy the jails.

  • At all created jails:

    In the playbook pb-test.yml:

    • connect to the created jails

    • display the basic jails’ configuration.

Requirements

Notes

Templates created in 202 Create iocage templates. Clone DHCP jails. are used in this example.

See also

Templates at iocage_02

[iocage_02]# iocage list -lt
+------+----------------+------+-------+----------+-----------------+--------------------+-----+----------+----------+
| JID  |      NAME      | BOOT | STATE |   TYPE   |     RELEASE     |        IP4         | IP6 | TEMPLATE | BASEJAIL |
+======+================+======+=======+==========+=================+====================+=====+==========+==========+
| None | ansible_client | off  | down  | template | 14.2-RELEASE-p3 | DHCP (not running) | -   | -        | no       |
+------+----------------+------+-------+----------+-----------------+--------------------+-----+----------+----------+

Templates at iocage_04

[iocage_04]# iocage list -lt
+------+----------------+------+-------+----------+-----------------+--------------------+-----+----------+----------+
| JID  |      NAME      | BOOT | STATE |   TYPE   |     RELEASE     |        IP4         | IP6 | TEMPLATE | BASEJAIL |
+======+================+======+=======+==========+=================+====================+=====+==========+==========+
| None | ansible_client | off  | down  | template | 14.3-RELEASE-p1 | DHCP (not running) | -   | -        | no       |
+------+----------------+------+-------+----------+-----------------+--------------------+-----+----------+----------+

ansible.cfg

[defaults]
gathering = explicit
callback_result_format = yaml
display_skipped_hosts = false

[connection]
pipelining = true

Inventory iocage.ini

iocage_02 ansible_host=10.1.0.73
iocage_04 ansible_host=10.1.0.29

[iocage]
iocage_02
iocage_04

[iocage:vars]
ansible_user=admin
ansible_become=true
ansible_python_interpreter=auto_silent

group_vars

group_vars/all/iocage.yml
properties:
  bpf: 1
  dhcp: 1
  vnet: 1
  notes: "vmm={{ inventory_hostname }}"

swarms:
  sw_01:
    count: 3
    template: ansible_client

Playbook pb-iocage-ansible-clients-v2.yml

---
- name: Create and start jails. Optionally stop and destroy jails.
  hosts: iocage
  environment: "{{ iocage_env | d({}) }}"

  vars:

    debug: false
    debug2: false
    dry_run: false

    swarm: false
    swarm_destroy: false
    clone: false
    clone_destroy: false

    _tags: "{{ dict(iocage_jails.keys()
                    | zip(iocage_jails.values()
                          | map(attribute='properties.notes')
                          | map('split')
                          | map('map', 'split', '=')
                          | map('community.general.dict'))) }}"
    _started: "{{ iocage_jails | dict2items
                               | selectattr('value.state', 'eq', 'up')
                               | map(attribute='key') }}"

  tasks:

    - name: Create and start swarms
      when: swarm | bool
      tags: swarm
      ansible.builtin.import_tasks: pb-iocage-ansible-clients-v2/swarm.yml

    - name: Stop and destroy swarms
      when: swarm_destroy | bool
      tags: swarm_destroy
      ansible.builtin.import_tasks: pb-iocage-ansible-clients-v2/swarm_destroy.yml

Playbook output - Create and start jails

(env) > ansible-playbook pb-iocage-ansible-clients-v2.yml \
                         -i iocage.ini \
                         -t swarm -e swarm=true -e debug=true
PLAY [Create and start jails. Optionally stop and destroy jails.] **************

TASK [Get iocage list of jails] ************************************************
ok: [iocage_04]
ok: [iocage_02]

TASK [Set dictionary iocage_jails] *********************************************
ok: [iocage_02]
ok: [iocage_04]

TASK [Set dictionary iocage_jails_properties] **********************************
ok: [iocage_02]
ok: [iocage_04]

TASK [Combine iocage_jails and iocage_jails_properties] ************************
ok: [iocage_02]
ok: [iocage_04]

TASK [Debug cmd_create debug=true] *********************************************
ok: [iocage_02] => (item=sw_01) => 
    msg: |-
        iocage create --short --template ansible_client --count 3 bpf=1 dhcp=1 vnet=1 notes="vmm=iocage_02  swarm=sw_01"
ok: [iocage_04] => (item=sw_01) => 
    msg: |-
        iocage create --short --template ansible_client --count 3 bpf=1 dhcp=1 vnet=1 notes="vmm=iocage_04  swarm=sw_01"

TASK [Create swarms] ***********************************************************
changed: [iocage_04] => (item=sw_01)
changed: [iocage_02] => (item=sw_01)

TASK [Debug create swarms debug=true] ******************************************
ok: [iocage_02] => 
    out:
        changed: true
        msg: All items completed
        results:
        -   ansible_loop_var: item
            changed: true
            cmd:
            - iocage
            - create
            - --short
            - --template
            - ansible_client
            - --count
            - '3'
            - bpf=1
            - dhcp=1
            - vnet=1
            - notes=vmm=iocage_02  swarm=sw_01
            delta: '0:00:04.276951'
            end: '2025-08-07 15:50:30.020336'
            failed: false
            invocation:
                module_args:
                    _raw_params: |-
                        iocage create --short --template ansible_client --count 3 bpf=1 dhcp=1 vnet=1 notes="vmm=iocage_02  swarm=sw_01"
                    _uses_shell: false
                    argv: null
                    chdir: null
                    creates: null
                    executable: null
                    expand_argument_vars: true
                    removes: null
                    stdin: null
                    stdin_add_newline: true
                    strip_empty_ends: true
            item:
                key: sw_01
                value:
                    count: 3
                    template: ansible_client
            msg: ''
            rc: 0
            start: '2025-08-07 15:50:25.743385'
            stderr: ''
            stderr_lines: []
            stdout: |-
                b9d2f97a successfully created!
                c33fe7bc successfully created!
                9da57e6d successfully created!
            stdout_lines:
            - b9d2f97a successfully created!
            - c33fe7bc successfully created!
            - 9da57e6d successfully created!
        skipped: false
ok: [iocage_04] => 
    out:
        changed: true
        msg: All items completed
        results:
        -   ansible_loop_var: item
            changed: true
            cmd:
            - iocage
            - create
            - --short
            - --template
            - ansible_client
            - --count
            - '3'
            - bpf=1
            - dhcp=1
            - vnet=1
            - notes=vmm=iocage_04  swarm=sw_01
            delta: '0:00:01.003907'
            end: '2025-08-07 15:50:38.560180'
            failed: false
            invocation:
                module_args:
                    _raw_params: |-
                        iocage create --short --template ansible_client --count 3 bpf=1 dhcp=1 vnet=1 notes="vmm=iocage_04  swarm=sw_01"
                    _uses_shell: false
                    argv: null
                    chdir: null
                    creates: null
                    executable: null
                    expand_argument_vars: true
                    removes: null
                    stdin: null
                    stdin_add_newline: true
                    strip_empty_ends: true
            item:
                key: sw_01
                value:
                    count: 3
                    template: ansible_client
            msg: ''
            rc: 0
            start: '2025-08-07 15:50:37.556273'
            stderr: ''
            stderr_lines: []
            stdout: |-
                262a357b successfully created!
                6dc099a5 successfully created!
                c4c3f57a successfully created!
            stdout_lines:
            - 262a357b successfully created!
            - 6dc099a5 successfully created!
            - c4c3f57a successfully created!
        skipped: false

TASK [Get iocage list of jails] ************************************************
ok: [iocage_04]
ok: [iocage_02]

TASK [Set dictionary iocage_jails] *********************************************
ok: [iocage_02]
ok: [iocage_04]

TASK [Get properties of iocage jails] ******************************************
ok: [iocage_04] => (item=262a357b)
ok: [iocage_04] => (item=6dc099a5)
ok: [iocage_04] => (item=c4c3f57a)
ok: [iocage_02] => (item=9da57e6d)
ok: [iocage_02] => (item=b9d2f97a)
ok: [iocage_02] => (item=c33fe7bc)

TASK [Set dictionary iocage_jails_properties] **********************************
ok: [iocage_02]
ok: [iocage_04]

TASK [Combine iocage_jails and iocage_jails_properties] ************************
ok: [iocage_02]
ok: [iocage_04]

TASK [Debug cmd_start debug=true] **********************************************
ok: [iocage_02] => (item=sw_01) => 
    msg: |-
        iocage start 9da57e6d b9d2f97a c33fe7bc
ok: [iocage_04] => (item=sw_01) => 
    msg: |-
        iocage start 262a357b 6dc099a5 c4c3f57a

TASK [Start swarms] ************************************************************
changed: [iocage_04] => (item=sw_01)
changed: [iocage_02] => (item=sw_01)

TASK [Debug start swarms debug=true] *******************************************
ok: [iocage_02] => 
    out:
        changed: true
        msg: All items completed
        results:
        -   ansible_loop_var: item
            changed: true
            cmd:
            - iocage
            - start
            - 9da57e6d
            - b9d2f97a
            - c33fe7bc
            delta: '0:00:33.543132'
            end: '2025-08-07 15:51:16.338307'
            failed: false
            invocation:
                module_args:
                    _raw_params: |-
                        iocage start 9da57e6d b9d2f97a c33fe7bc
                    _uses_shell: false
                    argv: null
                    chdir: null
                    creates: null
                    executable: null
                    expand_argument_vars: true
                    removes: null
                    stdin: null
                    stdin_add_newline: true
                    strip_empty_ends: true
            item:
                key: sw_01
                value:
                    count: 3
                    template: ansible_client
            msg: ''
            rc: 0
            start: '2025-08-07 15:50:42.795175'
            stderr: |-
                No default gateway found for ipv6.
                No default gateway found for ipv6.
                No default gateway found for ipv6.
            stderr_lines:
            - No default gateway found for ipv6.
            - No default gateway found for ipv6.
            - No default gateway found for ipv6.
            stdout: |-
                * Starting 9da57e6d
                  + Started OK
                  + Using devfs_ruleset: 1000 (iocage generated default)
                  + Configuring VNET OK
                  + Using IP options: vnet
                  + Starting services OK
                  + Executing poststart OK
                  + DHCP Address: 10.1.0.219/24
                * Starting b9d2f97a
                  + Started OK
                  + Using devfs_ruleset: 1001 (iocage generated default)
                  + Configuring VNET OK
                  + Using IP options: vnet
                  + Starting services OK
                  + Executing poststart OK
                  + DHCP Address: 10.1.0.152/24
                * Starting c33fe7bc
                  + Started OK
                  + Using devfs_ruleset: 1002 (iocage generated default)
                  + Configuring VNET OK
                  + Using IP options: vnet
                  + Starting services OK
                  + Executing poststart OK
                  + DHCP Address: 10.1.0.209/24
            stdout_lines:
            - '* Starting 9da57e6d'
            - '  + Started OK'
            - '  + Using devfs_ruleset: 1000 (iocage generated default)'
            - '  + Configuring VNET OK'
            - '  + Using IP options: vnet'
            - '  + Starting services OK'
            - '  + Executing poststart OK'
            - '  + DHCP Address: 10.1.0.219/24'
            - '* Starting b9d2f97a'
            - '  + Started OK'
            - '  + Using devfs_ruleset: 1001 (iocage generated default)'
            - '  + Configuring VNET OK'
            - '  + Using IP options: vnet'
            - '  + Starting services OK'
            - '  + Executing poststart OK'
            - '  + DHCP Address: 10.1.0.152/24'
            - '* Starting c33fe7bc'
            - '  + Started OK'
            - '  + Using devfs_ruleset: 1002 (iocage generated default)'
            - '  + Configuring VNET OK'
            - '  + Using IP options: vnet'
            - '  + Starting services OK'
            - '  + Executing poststart OK'
            - '  + DHCP Address: 10.1.0.209/24'
        skipped: false
ok: [iocage_04] => 
    out:
        changed: true
        msg: All items completed
        results:
        -   ansible_loop_var: item
            changed: true
            cmd:
            - iocage
            - start
            - 262a357b
            - 6dc099a5
            - c4c3f57a
            delta: '0:00:22.708665'
            end: '2025-08-07 15:51:17.264486'
            failed: false
            invocation:
                module_args:
                    _raw_params: |-
                        iocage start 262a357b 6dc099a5 c4c3f57a
                    _uses_shell: false
                    argv: null
                    chdir: null
                    creates: null
                    executable: null
                    expand_argument_vars: true
                    removes: null
                    stdin: null
                    stdin_add_newline: true
                    strip_empty_ends: true
            item:
                key: sw_01
                value:
                    count: 3
                    template: ansible_client
            msg: ''
            rc: 0
            start: '2025-08-07 15:50:54.555821'
            stderr: |-
                No default gateway found for ipv6.
                No default gateway found for ipv6.
                No default gateway found for ipv6.
            stderr_lines:
            - No default gateway found for ipv6.
            - No default gateway found for ipv6.
            - No default gateway found for ipv6.
            stdout: |-
                * Starting 262a357b
                  + Started OK
                  + Using devfs_ruleset: 1003 (iocage generated default)
                  + Configuring VNET OK
                  + Using IP options: vnet
                  + Starting services OK
                  + Executing poststart OK
                  + DHCP Address: 10.1.0.242/24
                * Starting 6dc099a5
                  + Started OK
                  + Using devfs_ruleset: 1004 (iocage generated default)
                  + Configuring VNET OK
                  + Using IP options: vnet
                  + Starting services OK
                  + Executing poststart OK
                  + DHCP Address: 10.1.0.140/24
                * Starting c4c3f57a
                  + Started OK
                  + Using devfs_ruleset: 1005 (iocage generated default)
                  + Configuring VNET OK
                  + Using IP options: vnet
                  + Starting services OK
                  + Executing poststart OK
                  + DHCP Address: 10.1.0.166/24
            stdout_lines:
            - '* Starting 262a357b'
            - '  + Started OK'
            - '  + Using devfs_ruleset: 1003 (iocage generated default)'
            - '  + Configuring VNET OK'
            - '  + Using IP options: vnet'
            - '  + Starting services OK'
            - '  + Executing poststart OK'
            - '  + DHCP Address: 10.1.0.242/24'
            - '* Starting 6dc099a5'
            - '  + Started OK'
            - '  + Using devfs_ruleset: 1004 (iocage generated default)'
            - '  + Configuring VNET OK'
            - '  + Using IP options: vnet'
            - '  + Starting services OK'
            - '  + Executing poststart OK'
            - '  + DHCP Address: 10.1.0.140/24'
            - '* Starting c4c3f57a'
            - '  + Started OK'
            - '  + Using devfs_ruleset: 1005 (iocage generated default)'
            - '  + Configuring VNET OK'
            - '  + Using IP options: vnet'
            - '  + Starting services OK'
            - '  + Executing poststart OK'
            - '  + DHCP Address: 10.1.0.166/24'
        skipped: false

PLAY RECAP *********************************************************************
iocage_02                  : ok=15   changed=2    unreachable=0    failed=0    skipped=3    rescued=0    ignored=0   
iocage_04                  : ok=15   changed=2    unreachable=0    failed=0    skipped=3    rescued=0    ignored=0   

Jails at iocage_02

[iocage_02]# iocage list -l
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| JID |   NAME   | BOOT | STATE | TYPE |     RELEASE     |        IP4         | IP6 |    TEMPLATE    | BASEJAIL |
+=====+==========+======+=======+======+=================+====================+=====+================+==========+
| 71  | 9da57e6d | off  | up    | jail | 14.2-RELEASE-p3 | epair0b|10.1.0.219 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| 72  | b9d2f97a | off  | up    | jail | 14.2-RELEASE-p3 | epair0b|10.1.0.152 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| 73  | c33fe7bc | off  | up    | jail | 14.2-RELEASE-p3 | epair0b|10.1.0.209 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+

Jails at iocage_04

[iocage_04]# iocage list -l
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| JID |   NAME   | BOOT | STATE | TYPE |     RELEASE     |        IP4         | IP6 |    TEMPLATE    | BASEJAIL |
+=====+==========+======+=======+======+=================+====================+=====+================+==========+
| 73  | 262a357b | off  | up    | jail | 14.3-RELEASE-p1 | epair0b|10.1.0.242 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| 74  | 6dc099a5 | off  | up    | jail | 14.3-RELEASE-p1 | epair0b|10.1.0.140 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| 75  | c4c3f57a | off  | up    | jail | 14.3-RELEASE-p1 | epair0b|10.1.0.166 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+

Inventory hosts

hosts/02_iocage.yml
plugin: vbotka.freebsd.iocage
host: 10.1.0.73
user: admin
get_properties: True
hooks_results:
  - /var/db/dhclient-hook.address.epair0b
compose:
  ansible_host: (iocage_hooks.0 == '-') | ternary(iocage_ip4, iocage_hooks.0)
  iocage_tags: dict(iocage_properties.notes | split | map('split', '='))
hosts/04_iocage.yml
plugin: vbotka.freebsd.iocage
host: 10.1.0.29
user: admin
get_properties: True
hooks_results:
  - /var/db/dhclient-hook.address.epair0b
compose:
  ansible_host: (iocage_hooks.0 == '-') | ternary(iocage_ip4, iocage_hooks.0)
  iocage_tags: dict(iocage_properties.notes | split | map('split', '='))
hosts/99_constructed.yml
plugin: ansible.builtin.constructed
keyed_groups:
  - prefix: swarm
    key: iocage_tags.swarm
  - prefix: vmm
    key: iocage_tags.vmm

Note

The option get_properties: True is needed to get the dictionary iocage_properties.

Display inventory

(env) > ansible-inventory -i hosts --graph
@all:
  |--@ungrouped:
  |--@swarm_sw_01:
  |  |--9da57e6d
  |  |--b9d2f97a
  |  |--c33fe7bc
  |  |--262a357b
  |  |--6dc099a5
  |  |--c4c3f57a
  |--@vmm_iocage_02:
  |  |--9da57e6d
  |  |--b9d2f97a
  |  |--c33fe7bc
  |--@vmm_iocage_04:
  |  |--262a357b
  |  |--6dc099a5
  |  |--c4c3f57a

Playbook pb-test.yml

- name: Connect to the group test.
  hosts: swarm_sw_01
  remote_user: admin
  gather_facts: false

  vars:

    ansible_python_interpreter: auto_silent
    
  tasks:

    - ansible.builtin.command: hostname
      register: out_host
    
    - ansible.builtin.debug:
        msg: >
          ansible_host={{ ansible_host }}
          iocage_tags={{ iocage_tags | to_yaml }}

Playbook output - Display iocage_tags

(env) > ansible-playbook pb-test.yml -i hosts
PLAY [Connect to the group test.] **********************************************

TASK [ansible.builtin.command] *************************************************
changed: [262a357b]
changed: [6dc099a5]
changed: [c4c3f57a]
changed: [b9d2f97a]
changed: [9da57e6d]
changed: [c33fe7bc]

TASK [ansible.builtin.debug] ***************************************************
ok: [9da57e6d] => 
    msg: |-
        ansible_host=10.1.0.219 iocage_tags={swarm: sw_01, vmm: iocage_02}
ok: [b9d2f97a] => 
    msg: |-
        ansible_host=10.1.0.152 iocage_tags={swarm: sw_01, vmm: iocage_02}
ok: [c33fe7bc] => 
    msg: |-
        ansible_host=10.1.0.209 iocage_tags={swarm: sw_01, vmm: iocage_02}
ok: [262a357b] => 
    msg: |-
        ansible_host=10.1.0.242 iocage_tags={swarm: sw_01, vmm: iocage_04}
ok: [6dc099a5] => 
    msg: |-
        ansible_host=10.1.0.140 iocage_tags={swarm: sw_01, vmm: iocage_04}
ok: [c4c3f57a] => 
    msg: |-
        ansible_host=10.1.0.166 iocage_tags={swarm: sw_01, vmm: iocage_04}

PLAY RECAP *********************************************************************
262a357b                   : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
6dc099a5                   : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
9da57e6d                   : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
b9d2f97a                   : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
c33fe7bc                   : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
c4c3f57a                   : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Hint

The below command stops and destroys the jails in swarms

ansible-playbook pb-iocage-ansible-clients-v2.yml \
                 -i iocage.ini \
                 -t swarm_destroy -e swarm_destroy=true