210 Test empty iocage notes

Use case

Test empty iocage notes. Create iocage_tags. The result should be an empty dictionary.

Tree

shell> tree .
.
├── ansible.cfg
├── hosts
│   └── 04_iocage.yml
├── iocage.ini
├── pb-iocage.yml
└── pb-test.yml

Synopsis

  • At the managed node iocage_04 in the playbook:

Requirements

Notes

TBD

Jails at iocage_04

[iocage_04]# iocage list -l
+------+--------+------+-------+------+-----------------+-----+-----+----------+----------+
| JID  |  NAME  | BOOT | STATE | TYPE |     RELEASE     | IP4 | IP6 | TEMPLATE | BASEJAIL |
+======+========+======+=======+======+=================+=====+=====+==========+==========+
| None | test_4 | off  | down  | jail | 14.3-RELEASE-p8 | -   | -   | -        | no       |
+------+--------+------+-------+------+-----------------+-----+-----+----------+----------+

ansible.cfg

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

[connection]
pipelining = true

Inventory iocage.ini

iocage_04 ansible_host=10.1.0.29

[iocage]
iocage_04

[iocage:vars]
ansible_user=admin
ansible_python_interpreter=auto_silent

Playbook pb-iocage.yml

- name: Test empty iocage notes.
  hosts: iocage_04

  tasks:

    - command: iocage get notes test_4
      register: out

    - debug:
        msg: |
          out.stdout: {{ out.stdout }}
          out.stdout type: {{ out.stdout | type_debug }}

Playbook output - display empty notes

(env) > ansible-playbook -i iocage.ini pb-iocage.yml
PLAY [Test empty iocage notes.] ************************************************

TASK [command] *****************************************************************
changed: [iocage_04]

TASK [debug] *******************************************************************
ok: [iocage_04] => 
    msg: |-
        out.stdout: none
        out.stdout type: str

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

Inventory hosts

hosts/04_iocage.yml
plugin: vbotka.freebsd.iocage
host: 10.1.0.29
user: admin
get_properties: true
compose:
  iocage_tags: dict(iocage_properties.notes | regex_findall('(\w+)=([\w\-]+)'))

Playbook pb-test.yml

- name: Test empty iocage notes.
  hosts: test_4

  tasks:

    - debug:
        msg: |
          iocage_properties.notes: {{ iocage_properties.notes }}
          iocage_properties.notes type: {{ iocage_properties.notes | type_debug }}

    - debug:
        var: iocage_tags

Playbook output - display empty iocage_tags

(env) > ansible-playbook -i hosts pb-test.yml
PLAY [Test empty iocage notes.] ************************************************

TASK [debug] *******************************************************************
ok: [test_4] => 
    msg: |-
        iocage_properties.notes: none
        iocage_properties.notes type: str

TASK [debug] *******************************************************************
ok: [test_4] => 
    iocage_tags: {}

PLAY RECAP *********************************************************************
test_4                     : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0