201 Display iocage lists and dictionaries

Extending example 200.

Use case

Create and display iocage lists and dictionaries.

Tree

shell> tree .
.
├── ansible.cfg
├── iocage-hosts.ini
└── pb-iocage-display-lists.yml

Synopsis

  • On two iocage hosts:

    • iocage_01

    • iocage_02

    In the playbook pb-iocage-display-lists.yml, use the module vbotka.freebsd.iocage to:

    • create and display iocage lists and dictionaries.

Notes

  • root is not needed to run ‘iocage list …’ on the iocage hosts when DHCP isn’t used.

  • Quoting from man iocage:

    list    List  the  specified dataset type.  By default, all jails are
            listed.
    
            Options:
    
            [--http]              Changes [-R | --remote] to use HTTP.
    
            [-H | -h | --header]  Used in scripting.  Use tabs for  sepa-
                                  rators.
    
            [-P | --plugins]      Shows plugins installed on the system.
    
            [-PRO]                Lists  official  plugins  available for
                                  download.
    
            [-R | --remote]       Shows available RELEASE options for re-
                                  mote.
    
            [-b | -r | --base | --release | dataset_type]
                                  List all bases.
    
            [-l | --long]         Shows JID, NAME, BOOT, STATE, TYPE, RE-
                                  LEASE, IP4, IP6, and TEMPLATE  informa-
                                  tion.
    
            [-q | --quick]        Lists  all  jails  with less processing
                                  and fields.
    
            [-s | --sort TEXT]    Sorts the list by the given type.
    
            [-t | --template | dataset_type]
                                  Lists all templates.
    

Lists at iocage_01

[iocage_01]# iocage list -r
+---------------+
| Bases fetched |
+===============+
| 13.3-RELEASE  |
+---------------+
| 13.4-RELEASE  |
+---------------+

[iocage_01]# iocage list -P
+-----+------+------+-------+------+---------+-----+-----+----------+--------+---------+
| JID | NAME | BOOT | STATE | TYPE | RELEASE | IP4 | IP6 | TEMPLATE | PORTAL | DOC_URL |
+=====+======+======+=======+======+=========+=====+=====+==========+========+=========+
+-----+------+------+-------+------+---------+-----+-----+----------+--------+---------+

[iocage_01]# iocage list -lt
+------+----------------+------+-------+----------+-----------------+---------------------+-----+----------+----------+
| JID  |      NAME      | BOOT | STATE |   TYPE   |     RELEASE     |         IP4         | IP6 | TEMPLATE | BASEJAIL |
+======+================+======+=======+==========+=================+=====================+=====+==========+==========+
| None | ansible_client | off  | down  | template | 13.4-RELEASE-p2 | vnet0|10.1.0.198/24 | -   | -        | no       |
+------+----------------+------+-------+----------+-----------------+---------------------+-----+----------+----------+

[iocage_01]# iocage list -l 
+-----+----------+------+-------+------+-----------------+---------------------+-----+----------------+----------+
| JID |   NAME   | BOOT | STATE | TYPE |     RELEASE     |         IP4         | IP6 |    TEMPLATE    | BASEJAIL |
+=====+==========+======+=======+======+=================+=====================+=====+================+==========+
| 134 | test_101 | off  | up    | jail | 13.4-RELEASE-p2 | vnet0|10.1.0.101/24 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+---------------------+-----+----------------+----------+
| 135 | test_102 | off  | up    | jail | 13.4-RELEASE-p2 | vnet0|10.1.0.102/24 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+---------------------+-----+----------------+----------+
| 136 | test_103 | off  | up    | jail | 13.4-RELEASE-p2 | vnet0|10.1.0.103/24 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+---------------------+-----+----------------+----------+

Lists at iocage_02

[iocage_02]# iocage list -r
+---------------+
| Bases fetched |
+===============+
| 14.1-RELEASE  |
+---------------+

[iocage_02]# iocage list -P
+-----+------+------+-------+------+---------+-----+-----+----------+--------+---------+
| JID | NAME | BOOT | STATE | TYPE | RELEASE | IP4 | IP6 | TEMPLATE | PORTAL | DOC_URL |
+=====+======+======+=======+======+=========+=====+=====+==========+========+=========+
+-----+------+------+-------+------+---------+-----+-----+----------+--------+---------+

[iocage_02]# iocage list -lt
+------+----------------+------+-------+----------+-----------------+-------------------+-----+----------+----------+
| JID  |      NAME      | BOOT | STATE |   TYPE   |     RELEASE     |        IP4        | IP6 | TEMPLATE | BASEJAIL |
+======+================+======+=======+==========+=================+===================+=====+==========+==========+
| None | ansible_client | off  | down  | template | 14.1-RELEASE-p6 | em0|10.1.0.199/24 | -   | -        | no       |
+------+----------------+------+-------+----------+-----------------+-------------------+-----+----------+----------+

[iocage_02]# iocage list -l
+-----+----------+------+-------+------+-----------------+-------------------+-----+----------------+----------+
| JID |   NAME   | BOOT | STATE | TYPE |     RELEASE     |        IP4        | IP6 |    TEMPLATE    | BASEJAIL |
+=====+==========+======+=======+======+=================+===================+=====+================+==========+
| 170 | test_111 | off  | up    | jail | 14.1-RELEASE-p6 | em0|10.1.0.111/24 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+-------------------+-----+----------------+----------+
| 171 | test_112 | off  | up    | jail | 14.1-RELEASE-p6 | em0|10.1.0.112/24 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+-------------------+-----+----------------+----------+
| 172 | test_113 | off  | up    | jail | 14.1-RELEASE-p6 | em0|10.1.0.113/24 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+-------------------+-----+----------------+----------+

Inventory iocage-hosts.ini

iocage_01 ansible_host=10.1.0.18
iocage_02 ansible_host=10.1.0.73

[iocage]
iocage_01
iocage_02

[iocage:vars]
ansible_user=admin
ansible_python_interpreter=auto_silent

Note

  • The escalation become=true is not necessary.

  • root is not needed to run ‘iocage list …’ when DHCP isn’t used.

  • admin executes the module vbotka.freebsd.iocage on the iocage hosts and creates the variables iocage_*

Playbook pb-iocage-display-lists.yml

- name: Display iocage lists and dictionaries.
  hosts: iocage
  environment:
    CRYPTOGRAPHY_OPENSSL_NO_LEGACY: 1
    
  tasks:

    - name: Set iocage lists and dictionaries.
      vbotka.freebsd.iocage:

    - name: Display iocage lists and dictionaries (omit properties).
      vars:
        tkeys: "{{ iocage_templates.keys() }}"
        tvals: "{{ iocage_templates.values()
                   | list                       
                   | community.general.remove_keys(target=['properties']) }}"
        jkeys: "{{ iocage_jails.keys() }}"
        jvals: "{{ iocage_jails.values()
                   | list                       
                   | community.general.remove_keys(target=['properties']) }}"
      ansible.builtin.debug:
        msg: |
          iocage_releases: {{ iocage_releases }}
          iocage_plugins:
            {{ iocage_plugins | to_nice_yaml(indent=2) | indent(2) }}
          iocage_templates:
            {{ dict(tkeys|zip(tvals)) | to_nice_yaml(indent=2) | indent(2) }}
          iocage_jails:
            {{ dict(jkeys|zip(jvals)) | to_nice_yaml(indent=2) | indent(2) }}

    - name: "Display templates and jails properties={{ properties | d(false) }}"
      when: properties | d(false) | bool
      ansible.builtin.debug:
        msg: |
          iocage_templates:
            {{ iocage_templates | to_nice_yaml(indent=2) | indent(2) }}
          iocage_jails:
            {{ iocage_jails | to_nice_yaml(indent=2) | indent(2) }}

Playbook output

(env) > ansible-playbook pb-iocage-display-lists.yml -i iocage-hosts.ini 

PLAY [Display iocage lists and dictionaries.] **************************************************

TASK [Set iocage lists and dictionaries.] ******************************************************
ok: [iocage_01]
ok: [iocage_02]

TASK [Display iocage lists and dictionaries (omit properties).] ********************************
ok: [iocage_01] => 
    msg: |-
        iocage_releases: ['13.3-RELEASE', '13.4-RELEASE']
        iocage_plugins:
          {}

        iocage_templates:
          ansible_client:
            basejail: 'no'
            boot: 'off'
            ip4: vnet0|10.1.0.198/24
            ip6: '-'
            jid: '-'
            name: ansible_client
            release: 13.4-RELEASE-p2
            state: down
            template: '-'
            type: template

        iocage_jails:
          test_101:
            basejail: 'no'
            boot: 'off'
            ip4: vnet0|10.1.0.101/24
            ip6: '-'
            jid: '134'
            name: test_101
            release: 13.4-RELEASE-p2
            state: up
            template: ansible_client
            type: jail
          test_102:
            basejail: 'no'
            boot: 'off'
            ip4: vnet0|10.1.0.102/24
            ip6: '-'
            jid: '135'
            name: test_102
            release: 13.4-RELEASE-p2
            state: up
            template: ansible_client
            type: jail
          test_103:
            basejail: 'no'
            boot: 'off'
            ip4: vnet0|10.1.0.103/24
            ip6: '-'
            jid: '136'
            name: test_103
            release: 13.4-RELEASE-p2
            state: up
            template: ansible_client
            type: jail
ok: [iocage_02] => 
    msg: |-
        iocage_releases: ['14.1-RELEASE']
        iocage_plugins:
          {}

        iocage_templates:
          ansible_client:
            basejail: 'no'
            boot: 'off'
            ip4: em0|10.1.0.199/24
            ip6: '-'
            jid: None
            name: ansible_client
            release: 14.1-RELEASE-p6
            state: down
            template: '-'
            type: template

        iocage_jails:
          test_111:
            basejail: 'no'
            boot: 'off'
            ip4: em0|10.1.0.111/24
            ip6: '-'
            jid: '170'
            name: test_111
            release: 14.1-RELEASE-p6
            state: up
            template: ansible_client
            type: jail
          test_112:
            basejail: 'no'
            boot: 'off'
            ip4: em0|10.1.0.112/24
            ip6: '-'
            jid: '171'
            name: test_112
            release: 14.1-RELEASE-p6
            state: up
            template: ansible_client
            type: jail
          test_113:
            basejail: 'no'
            boot: 'off'
            ip4: em0|10.1.0.113/24
            ip6: '-'
            jid: '172'
            name: test_113
            release: 14.1-RELEASE-p6
            state: up
            template: ansible_client
            type: jail

TASK [Display templates and jails properties=False] ********************************************
skipping: [iocage_01]
skipping: [iocage_02]

PLAY RECAP *************************************************************************************
iocage_01: ok=2    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0
iocage_02: ok=2    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0