(WIP) 030 Create Ansible client template and clone Ansible client jails.¶
Tree¶
shell> tree .
.
├── ansible.cfg
├── files
│ └── pk_admins.txt
├── hosts
│ ├── 01_iocage.yml
│ ├── 02_iocage.yml
│ ├── 03_iocage.yml
│ └── 04_constructed.yml
├── host_vars
│ ├── iocage_01
│ │ └── iocage.yml
│ ├── iocage_02
│ │ └── iocage.yml
│ └── iocage_03
│ └── iocage.yml
├── iocage-hosts.ini
├── pb-iocage-ansible-clients.yml
├── pb-iocage-template.yml
└── tasks
├── basejails_create.yml
├── basejails_pkg.yml
├── basejails_start.yml
├── basejails_stop.yml
└── setup.yml
Synopsis¶
(WIP)
On three iocage hosts:
iocage_01
iocage_02
iocage_03
In the playbook pb-iocage-template.yml, use the module vbotka.freebsd.iocage to:
create Ansible client template.
In the playbook pb-iocage-ansible-clients.yml, use the module vbotka.freebsd.iocage to:
clone jails from the Ansible client template
start all jails
optionally display the lists of jails.
In the playbook pb-test-01.yml:
connect created jails
audit basic configuration of the jails.
Requirements¶
module vbotka.freebsd.iocage
inventory plugin vbotka.freebsd.iocage
root privilege on the iocage hosts
activated iocage
fetched releases
Notes¶
See also
host_vars/iocage_01/iocage.yml¶
ansible_python_interpreter: /usr/local/bin/python3.9
ansible_become_password: admin
freebsd_iocage_pool: pool2
freebsd_iocage_pool_mount: /mnt/pool2
freebsd_iocage_mount: "{{ freebsd_iocage_pool_mount }}/iocage"
properties:
vnet: 'on'
defaultrouter: 10.1.0.10
notes: "vmm={{ inventory_hostname }}"
fetch:
- 13.3-RELEASE
- 13.4-RELEASE
basejails:
- name: ansible_client
release: 13.4-RELEASE
properties:
ip4_addr: 'vnet0|10.1.0.198/24'
clones:
- name: test_101
clone_from: ansible_client
properties:
ip4_addr: 'vnet0|10.1.0.101/24'
- name: test_102
clone_from: ansible_client
properties:
ip4_addr: 'vnet0|10.1.0.102/24'
- name: test_103
clone_from: ansible_client
properties:
ip4_addr: 'vnet0|10.1.0.103/24'
start: [test_101, test_102, test_103]
host_vars/iocage_02/iocage.yml¶
ansible_python_interpreter: /usr/local/bin/python3.11
freebsd_iocage_runner_env:
CRYPTOGRAPHY_OPENSSL_NO_LEGACY: 1
freebsd_iocage_pool: zroot
freebsd_iocage_pool_mount: /zroot
freebsd_iocage_mount: "{{ freebsd_iocage_pool_mount }}/iocage"
properties:
notes: "vmm={{ inventory_hostname }}"
fetch:
- 14.1-RELEASE
basejails:
- name: ansible_client
release: 14.1-RELEASE
properties:
ip4_addr: 'em0|10.1.0.199/24'
clones:
- name: test_111
clone_from: ansible_client
properties:
ip4_addr: 'em0|10.1.0.111/24'
- name: test_112
clone_from: ansible_client
properties:
ip4_addr: 'em0|10.1.0.112/24'
- name: test_113
clone_from: ansible_client
properties:
ip4_addr: 'em0|10.1.0.113/24'
start: [test_111, test_112, test_113]
# ansible client template
act_user: admin
act_pkg:
- security/sudo
- lang/python311
act_pk:
- pk_admins.txt
host_vars/iocage_03/iocage.yml¶
ansible_python_interpreter: /usr/local/bin/python3.11
freebsd_iocage_runner_env:
CRYPTOGRAPHY_OPENSSL_NO_LEGACY: 1
freebsd_iocage_pool: zroot
freebsd_iocage_pool_mount: /zroot
freebsd_iocage_mount: "{{ freebsd_iocage_pool_mount }}/iocage"
properties:
notes: "vmm={{ inventory_hostname }}"
fetch:
- 14.2-RELEASE
basejails:
- name: ansible_client
release: 14.2-RELEASE
properties:
ip4_addr: 'ue0|10.1.0.197/24'
clones:
- name: test_121
clone_from: ansible_client
properties:
ip4_addr: 'ue0|10.1.0.121/24'
- name: test_112
clone_from: ansible_client
properties:
ip4_addr: 'ue0|10.1.0.122/24'
- name: test_113
clone_from: ansible_client
properties:
ip4_addr: 'ue0|10.1.0.123/24'
start: [test_121, test_122, test_123]
Inventory iocage-hosts.ini¶
iocage_01 ansible_host=10.1.0.18
iocage_02 ansible_host=10.1.0.73
iocage_03 ansible_host=10.1.0.28
[iocage]
iocage_01
iocage_02
iocage_03
[iocage:vars]
ansible_user=admin
ansible_become=true
Playbook pb-iocage-template.yml¶
- name: Create Ansible client templates.
hosts: iocage
environment: "{{ freebsd_iocage_runner_env | d({}) }}"
vars:
debug: false
debug2: false
basejails_stop: false
tasks:
- name: Setup
tags: [always, setup]
import_tasks: tasks/setup.yml
- name: Basejails create
tags: basejails_create
import_tasks: tasks/basejails_create.yml
- name: Basejails start
tags: basejails_start
import_tasks: tasks/basejails_start.yml
- name: Basejails install packages
tags: basejails_pkg
import_tasks: tasks/basejails_pkg.yml
- name: Basejails stop
when: basejails_stop | bool
tags: basejails_stop
import_tasks: tasks/basejails_stop.yml
Playbook output¶
(env) > ansible-playbook -i iocage-hosts.ini pb-iocage-template.yml
PLAY [iocage] *******************************************************************************************************
PLAY RECAP **********************************************************************************************************
iocage_01: ok=6 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
iocage_02: ok=6 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
List templates at iocage_01¶
[iocage_01]# iocage list -l
+------+----------------+------+-------+------+-----------------+---------------------+-----+----------------+----------+
| JID | NAME | BOOT | STATE | TYPE | RELEASE | IP4 | IP6 | TEMPLATE | BASEJAIL |
+======+================+======+=======+======+=================+=====================+=====+================+==========+
| None | ansible_client | off | down | jail | 13.4-RELEASE-p2 | - | - | - | yes |
+------+----------------+------+-------+------+-----------------+---------------------+-----+----------------+----------+
| None | test_101 | off | down | jail | 13.4-RELEASE-p2 | vnet0|10.1.0.101/24 | - | ansible_client | yes |
+------+----------------+------+-------+------+-----------------+---------------------+-----+----------------+----------+
| None | test_102 | off | down | jail | 13.4-RELEASE-p2 | vnet0|10.1.0.102/24 | - | ansible_client | yes |
+------+----------------+------+-------+------+-----------------+---------------------+-----+----------------+----------+
| 43 | test_103 | off | up | jail | 13.4-RELEASE-p2 | vnet0|10.1.0.103/24 | - | ansible_client | yes |
+------+----------------+------+-------+------+-----------------+---------------------+-----+----------------+----------+
List templates at iocage_02¶
[iocage_02]# iocage list -l
+------+----------------+------+-------+------+--------------+-------------------+-----+----------------+----------+
| JID | NAME | BOOT | STATE | TYPE | RELEASE | IP4 | IP6 | TEMPLATE | BASEJAIL |
+======+================+======+=======+======+==============+===================+=====+================+==========+
| None | ansible_client | off | down | jail | 14.1-RELEASE | - | - | - | yes |
+------+----------------+------+-------+------+--------------+-------------------+-----+----------------+----------+
| None | test_111 | off | down | jail | 14.1-RELEASE | em0|10.1.0.111/24 | - | ansible_client | yes |
+------+----------------+------+-------+------+--------------+-------------------+-----+----------------+----------+
| None | test_112 | off | down | jail | 14.1-RELEASE | em0|10.1.0.112/24 | - | ansible_client | yes |
+------+----------------+------+-------+------+--------------+-------------------+-----+----------------+----------+
| 60 | test_113 | off | up | jail | 14.1-RELEASE | em0|10.1.0.113/24 | - | ansible_client | yes |
+------+----------------+------+-------+------+--------------+-------------------+-----+----------------+----------+
Playbook pb-iocage-ansible-clients.yml¶
- name: Create ansible clients.
hosts: iocage
environment:
CRYPTOGRAPHY_OPENSSL_NO_LEGACY: 1
tasks:
- debug:
msg: WIP
Playbook output¶
(env) > ansible-playbook -i iocage-hosts.ini pb-iocage-ansible-clients.yml
Inventory hosts/01_iocage.yml¶
plugin: community.general.iocage
host: 10.1.0.18
user: admin
get_properties: true
env:
CRYPTOGRAPHY_OPENSSL_NO_LEGACY: 1
compose:
ansible_host: iocage_ip4
groups:
test_01: inventory_hostname.startswith('test')
Inventory hosts/02_iocage.yml¶
plugin: community.general.iocage
host: 10.1.0.73
user: admin
get_properties: true
env:
CRYPTOGRAPHY_OPENSSL_NO_LEGACY: 1
compose:
ansible_host: iocage_ip4
groups:
test_02: inventory_hostname.startswith('test')
Inventory hosts/03_iocage.yml¶
plugin: community.general.iocage
host: 10.1.0.28
user: admin
get_properties: true
env:
CRYPTOGRAPHY_OPENSSL_NO_LEGACY: 1
compose:
ansible_host: iocage_ip4
groups:
test_03: inventory_hostname.startswith('test')
Inventory hosts/04_constructed.yml¶
plugin: ansible.builtin.constructed
groups:
test: inventory_hostname.startswith('test')
Display inventory¶
(env) > ansible-inventory -i iocage.ini --list --yaml
Playbook pb-test-01.yml¶
- hosts: test
tasks:
- debug:
msg: |
inventory_hostname: {{ inventory_hostname }}
ansible_host: {{ ansible_host }}
release: {{ release }}
release_major: {{ release_major }}
release_minor: {{ release_minor }}
- debug:
msg: |
groups:
{{ groups | to_yaml(indent=2) | indent(2) }}
run_once: true
Playbook output¶
(env) > ansible-playbook -i iocage.ini pb-test-01.yml