050 Connection jailexec

Use case

Test the connection plugin vbotka.freebsd.jailexec

Tree

shell> tree .
.
├── ansible.cfg
├── hosts
│   ├── 01-iocage.ini
│   └── 02-iocage.yml
├── jailexec.ini
└── pb.yml

Synopsis

At an iocage node test the connection plugin vbotka.freebsd.jailexec

Requirements

TBD

Notes

  • The jails are not dynamically updated in the inventory file jailexec.ini.

ansible.cfg

ansible.cfg
[defaults]
callback_result_format = yaml
display_skipped_hosts = false
gathering = explicit
inventory = $PWD/hosts

[connection]
pipelining = true

Inventory of iocage nodes

hosts/01-iocage.ini
iocage_05 ansible_host=handy

[iocage]
iocage_05

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

Dynamic inventory of the jails

hosts/02-iocage.yml
plugin: vbotka.freebsd.iocage
host: iocage_05
user: admin
sudo: true

Inventory jailexec.ini

jailexec.ini
[jail_hosts]
iocage_05 ansible_connection=ssh ansible_user=admin

[jails]
cb040eb9 ansible_jail_name=1
dd911c4f ansible_jail_name=2
f20ab29e ansible_jail_name=3

[jails:vars]
ansible_user=admin
ansible_jail_host=iocage_05
ansible_connection=vbotka.freebsd.jailexec
ansible_jail_privilege_escalation=sudo
ansible_python_interpreter=auto_silent

Display the inventory of jails

(env) > ansible-inventory --list --yaml
all:
  children:
    iocage:
      hosts:
        iocage_05:
          ansible_become: 'true'
          ansible_host: handy
          ansible_python_interpreter: auto_silent
          ansible_user: admin
    ungrouped:
      hosts:
        cb040eb9:
          iocage_basejail: 'no'
          iocage_boot: 'off'
          iocage_ip4: 192.168.99.100
          iocage_ip4_dict:
            ip4:
            - ifc: epair0b
              ip: 192.168.99.100
              mask: '-'
            msg: ''
          iocage_ip6: '-'
          iocage_jid: '1'
          iocage_release: 15.0-RELEASE
          iocage_state: up
          iocage_template: ansible_client
          iocage_type: jail
        dd911c4f:
          iocage_basejail: 'no'
          iocage_boot: 'off'
          iocage_ip4: 192.168.99.101
          iocage_ip4_dict:
            ip4:
            - ifc: epair0b
              ip: 192.168.99.101
              mask: '-'
            msg: ''
          iocage_ip6: '-'
          iocage_jid: '2'
          iocage_release: 15.0-RELEASE
          iocage_state: up
          iocage_template: ansible_client
          iocage_type: jail
        f20ab29e:
          iocage_basejail: 'no'
          iocage_boot: 'off'
          iocage_ip4: 192.168.99.102
          iocage_ip4_dict:
            ip4:
            - ifc: epair0b
              ip: 192.168.99.102
              mask: '-'
            msg: ''
          iocage_ip6: '-'
          iocage_jid: '3'
          iocage_release: 15.0-RELEASE
          iocage_state: up
          iocage_template: ansible_client
          iocage_type: jail

Playbook pb.yml

- name: Test the connection plugin vbotka.freebsd.jailexec
  hosts: jails

  tasks:

    - command: hostname
      register: out

    - debug:
        var: out.stdout

Playbook output

(env) > ansible-playbook -i jailexec.ini pb.yml
PLAY [Test the connection plugin vbotka.freebsd.jailexec] **********************

TASK [command] *****************************************************************
changed: [f20ab29e]
changed: [cb040eb9]
changed: [dd911c4f]

TASK [debug] *******************************************************************
ok: [cb040eb9] => 
    out.stdout: cb040eb9
ok: [dd911c4f] => 
    out.stdout: dd911c4f
ok: [f20ab29e] => 
    out.stdout: f20ab29e

PLAY RECAP *********************************************************************
cb040eb9                   : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
dd911c4f                   : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
f20ab29e                   : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0