201 Display iocage datasets

Extending example 200 Create iocage templates. Clone jails..

Use case

Get and display iocage datasets.

Tree

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

Synopsis

  • At two managed nodes:

    • iocage_02

    • iocage_04

    In the playbook pb-iocage-display-datasets.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 separators.
    
            [-P | --plugins]      Shows plugins installed on the system.
    
            [-PRO]                Lists official plugins available for download.
    
            [-R | --remote]       Shows available RELEASE options for remote.
    
            [-b | -r | --base | --release | dataset_type]
                                  List all bases.
    
            [-l | --long]         Shows JID, NAME, BOOT, STATE, TYPE, RELEASE, IP4,
                                  IP6, and TEMPLATE  information.
    
            [-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.
    

Datasets at iocage_02

[iocage_02]# iocage list -r
+---------------+
| Bases fetched |
+===============+
| 14.2-RELEASE  |
+---------------+
| 14.3-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 |
+=====+======+======+=======+======+=========+=====+=====+==========+==========+
+-----+------+------+-------+------+---------+-----+-----+----------+----------+
[iocage_02]# iocage list -l
+------+----------------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| JID  |      NAME      | BOOT | STATE | TYPE |     RELEASE     |        IP4         | IP6 |    TEMPLATE    | BASEJAIL |
+======+================+======+=======+======+=================+====================+=====+================+==========+
| None | ansible_client | off  | down  | jail | 14.2-RELEASE-p3 | -                  | -   | -              | yes      |
+------+----------------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| 54   | test_111       | off  | up    | jail | 14.2-RELEASE-p3 | epair0b|10.1.0.175 | -   | ansible_client | yes      |
+------+----------------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| None | test_112       | off  | down  | jail | 14.2-RELEASE-p3 | DHCP (not running) | -   | ansible_client | yes      |
+------+----------------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| None | test_113       | off  | down  | jail | 14.2-RELEASE-p3 | DHCP (not running) | -   | ansible_client | yes      |
+------+----------------+------+-------+------+-----------------+--------------------+-----+----------------+----------+

Datasets at iocage_04

[iocage_04]# iocage list -r
+---------------+
| Bases fetched |
+===============+
| 14.3-RELEASE  |
+---------------+
[iocage_04]# iocage list -P
+-----+------+------+-------+------+---------+-----+-----+----------+--------+---------+
| JID | NAME | BOOT | STATE | TYPE | RELEASE | IP4 | IP6 | TEMPLATE | PORTAL | DOC_URL |
+=====+======+======+=======+======+=========+=====+=====+==========+========+=========+
+-----+------+------+-------+------+---------+-----+-----+----------+--------+---------+
[iocage_04]# iocage list -lt
+-----+------+------+-------+------+---------+-----+-----+----------+----------+
| JID | NAME | BOOT | STATE | TYPE | RELEASE | IP4 | IP6 | TEMPLATE | BASEJAIL |
+=====+======+======+=======+======+=========+=====+=====+==========+==========+
+-----+------+------+-------+------+---------+-----+-----+----------+----------+
[iocage_04]# iocage list -l
+------+----------------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| JID  |      NAME      | BOOT | STATE | TYPE |     RELEASE     |        IP4         | IP6 |    TEMPLATE    | BASEJAIL |
+======+================+======+=======+======+=================+====================+=====+================+==========+
| None | ansible_client | off  | down  | jail | 14.3-RELEASE-p1 | -                  | -   | -              | yes      |
+------+----------------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| 56   | test_131       | off  | up    | jail | 14.3-RELEASE-p1 | epair0b|10.1.0.207 | -   | ansible_client | yes      |
+------+----------------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| 57   | test_132       | off  | up    | jail | 14.3-RELEASE-p1 | epair0b|10.1.0.168 | -   | ansible_client | yes      |
+------+----------------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| 58   | test_133       | off  | up    | jail | 14.3-RELEASE-p1 | epair0b|10.1.0.208 | -   | ansible_client | yes      |
+------+----------------+------+-------+------+-----------------+--------------------+-----+----------------+----------+

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_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-datasets.yml

- name: Display iocage datasets.
  hosts: iocage
  environment:
    CRYPTOGRAPHY_OPENSSL_NO_LEGACY: 1
    
  tasks:

    - name: Get iocage datasets.
      vbotka.freebsd.iocage:

    - name: Display iocage datasets (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 - Display iocage datasets

(env) > ansible-playbook pb-iocage-display-datasets.yml -i iocage.ini
PLAY [Display iocage datasets.] ************************************************

TASK [Get iocage datasets.] ****************************************************
ok: [iocage_04]
ok: [iocage_02]

TASK [Display iocage datasets (omit properties).] ******************************
ok: [iocage_02] => 
    msg: |-
        iocage_releases: ['14.2-RELEASE', '14.3-RELEASE']
        iocage_plugins:
          {}

        iocage_templates:
          {}

        iocage_jails:
          ansible_client:
            basejail: 'yes'
            boot: 'off'
            ip4: '-'
            ip6: '-'
            jid: None
            name: ansible_client
            release: 14.2-RELEASE-p3
            state: down
            template: '-'
            type: jail
          test_111:
            basejail: 'yes'
            boot: 'off'
            ip4: DHCP (running -- address requires root)
            ip6: '-'
            jid: '54'
            name: test_111
            release: 14.2-RELEASE-p3
            state: up
            template: ansible_client
            type: jail
          test_112:
            basejail: 'yes'
            boot: 'off'
            ip4: DHCP (not running)
            ip6: '-'
            jid: None
            name: test_112
            release: 14.2-RELEASE-p3
            state: down
            template: ansible_client
            type: jail
          test_113:
            basejail: 'yes'
            boot: 'off'
            ip4: DHCP (not running)
            ip6: '-'
            jid: None
            name: test_113
            release: 14.2-RELEASE-p3
            state: down
            template: ansible_client
            type: jail
ok: [iocage_04] => 
    msg: |-
        iocage_releases: ['14.3-RELEASE']
        iocage_plugins:
          {}

        iocage_templates:
          {}

        iocage_jails:
          ansible_client:
            basejail: 'yes'
            boot: 'off'
            ip4: '-'
            ip6: '-'
            jid: None
            name: ansible_client
            release: 14.3-RELEASE-p1
            state: down
            template: '-'
            type: jail
          test_131:
            basejail: 'yes'
            boot: 'off'
            ip4: DHCP (running -- address requires root)
            ip6: '-'
            jid: '56'
            name: test_131
            release: 14.3-RELEASE-p1
            state: up
            template: ansible_client
            type: jail
          test_132:
            basejail: 'yes'
            boot: 'off'
            ip4: DHCP (running -- address requires root)
            ip6: '-'
            jid: '57'
            name: test_132
            release: 14.3-RELEASE-p1
            state: up
            template: ansible_client
            type: jail
          test_133:
            basejail: 'yes'
            boot: 'off'
            ip4: DHCP (running -- address requires root)
            ip6: '-'
            jid: '58'
            name: test_133
            release: 14.3-RELEASE-p1
            state: up
            template: ansible_client
            type: jail

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