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 |
+======+================+======+=======+==========+=================+====================+=====+==========+==========+
| None | ansible_client | off  | down  | template | 14.3-RELEASE-p8 | DHCP (not running) | -   | -        | no       |
+------+----------------+------+-------+----------+-----------------+--------------------+-----+----------+----------+
[iocage_02]# iocage list -l
+-----+----------+------+-------+------+-----------------+-------------------+-----+----------------+----------+
| JID |   NAME   | BOOT | STATE | TYPE |     RELEASE     |        IP4        | IP6 |    TEMPLATE    | BASEJAIL |
+=====+==========+======+=======+======+=================+===================+=====+================+==========+
| 74  | test_111 | off  | up    | jail | 14.3-RELEASE-p8 | em0|10.1.0.111/24 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+-------------------+-----+----------------+----------+
| 75  | test_112 | off  | up    | jail | 14.3-RELEASE-p8 | em0|10.1.0.112/24 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+-------------------+-----+----------------+----------+
| 76  | test_113 | off  | up    | jail | 14.3-RELEASE-p8 | em0|10.1.0.113/24 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+-------------------+-----+----------------+----------+

Datasets at iocage_04

[iocage_04]# iocage list -r
+---------------+
| Bases fetched |
+===============+
| 14.3-RELEASE  |
+---------------+
| 15.0-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 |
+======+=======================+======+=======+==========+=================+====================+=====+==========+==========+
| None | ansible_client        | off  | down  | template | 15.0-RELEASE-p3 | DHCP (not running) | -   | -        | no       |
+------+-----------------------+------+-------+----------+-----------------+--------------------+-----+----------+----------+
| None | ansible_client_apache | off  | down  | template | 15.0-RELEASE-p3 | DHCP (not running) | -   | -        | no       |
+------+-----------------------+------+-------+----------+-----------------+--------------------+-----+----------+----------+
| None | ansible_client_pull   | off  | down  | template | 15.0-RELEASE-p3 | DHCP (not running) | -   | -        | no       |
+------+-----------------------+------+-------+----------+-----------------+--------------------+-----+----------+----------+
[iocage_04]# iocage list -l
+-----+----------+------+-------+------+-----------------+---------------------+-----+----------------+----------+
| JID |   NAME   | BOOT | STATE | TYPE |     RELEASE     |         IP4         | IP6 |    TEMPLATE    | BASEJAIL |
+=====+==========+======+=======+======+=================+=====================+=====+================+==========+
| 53  | test_131 | off  | up    | jail | 15.0-RELEASE-p3 | vnet0|10.1.0.131/24 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+---------------------+-----+----------------+----------+
| 54  | test_132 | off  | up    | jail | 15.0-RELEASE-p3 | vnet0|10.1.0.132/24 | -   | ansible_client | no       |
+-----+----------+------+-------+------+-----------------+---------------------+-----+----------------+----------+
| 55  | test_133 | off  | up    | jail | 15.0-RELEASE-p3 | vnet0|10.1.0.133/24 | -   | ansible_client | 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_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: "{{ ansible_facts.iocage_templates.keys() }}"
        tvals: "{{ ansible_facts.iocage_templates.values()
                   | list                       
                   | community.general.remove_keys(target=['properties']) }}"
        jkeys: "{{ ansible_facts.iocage_jails.keys() }}"
        jvals: "{{ ansible_facts.iocage_jails.values()
                   | list                       
                   | community.general.remove_keys(target=['properties']) }}"
      ansible.builtin.debug:
        msg: |
          iocage_releases: {{ ansible_facts.iocage_releases }}
          iocage_plugins:
            {{ ansible_facts.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:
            {{ ansible_facts.iocage_templates | to_nice_yaml(indent=2) | indent(2) }}
          iocage_jails:
            {{ ansible_facts.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_04] => 
    msg: |-
        iocage_releases: ['14.3-RELEASE', '15.0-RELEASE']
        iocage_plugins:
          {}

        iocage_templates:
          ansible_client:
            basejail: 'no'
            boot: 'off'
            ip4: DHCP (not running)
            ip6: '-'
            jid: None
            name: ansible_client
            release: 15.0-RELEASE-p3
            state: down
            template: '-'
            type: template
          ansible_client_apache:
            basejail: 'no'
            boot: 'off'
            ip4: DHCP (not running)
            ip6: '-'
            jid: None
            name: ansible_client_apache
            release: 15.0-RELEASE-p3
            state: down
            template: '-'
            type: template
          ansible_client_pull:
            basejail: 'no'
            boot: 'off'
            ip4: DHCP (not running)
            ip6: '-'
            jid: None
            name: ansible_client_pull
            release: 15.0-RELEASE-p3
            state: down
            template: '-'
            type: template

        iocage_jails:
          test_131:
            basejail: 'no'
            boot: 'off'
            ip4: vnet0|10.1.0.131/24
            ip6: '-'
            jid: '53'
            name: test_131
            release: 15.0-RELEASE-p3
            state: up
            template: ansible_client
            type: jail
          test_132:
            basejail: 'no'
            boot: 'off'
            ip4: vnet0|10.1.0.132/24
            ip6: '-'
            jid: '54'
            name: test_132
            release: 15.0-RELEASE-p3
            state: up
            template: ansible_client
            type: jail
          test_133:
            basejail: 'no'
            boot: 'off'
            ip4: vnet0|10.1.0.133/24
            ip6: '-'
            jid: '55'
            name: test_133
            release: 15.0-RELEASE-p3
            state: up
            template: ansible_client
            type: jail
ok: [iocage_02] => 
    msg: |-
        iocage_releases: ['14.2-RELEASE', '14.3-RELEASE']
        iocage_plugins:
          {}

        iocage_templates:
          ansible_client:
            basejail: 'no'
            boot: 'off'
            ip4: DHCP (not running)
            ip6: '-'
            jid: None
            name: ansible_client
            release: 14.3-RELEASE-p8
            state: down
            template: '-'
            type: template

        iocage_jails:
          test_111:
            basejail: 'no'
            boot: 'off'
            ip4: em0|10.1.0.111/24
            ip6: '-'
            jid: '74'
            name: test_111
            release: 14.3-RELEASE-p8
            state: up
            template: ansible_client
            type: jail
          test_112:
            basejail: 'no'
            boot: 'off'
            ip4: em0|10.1.0.112/24
            ip6: '-'
            jid: '75'
            name: test_112
            release: 14.3-RELEASE-p8
            state: up
            template: ansible_client
            type: jail
          test_113:
            basejail: 'no'
            boot: 'off'
            ip4: em0|10.1.0.113/24
            ip6: '-'
            jid: '76'
            name: test_113
            release: 14.3-RELEASE-p8
            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