017 Inventory plugin community.general.iocage¶
Extending example 016.
Use case¶
Use the inventory plugin community.general.iocage instead of the inventory plugin vbotka.freebsd.iocage.
Tree¶
shell> tree .
.
├── ansible.cfg
├── hosts
│ ├── 01_iocage.yml
│ ├── 02_iocage.yml
│ └── 03_constructed.yml
├── pb-iocage-obsolete.yml
└── pb-test.yml
Synopsis¶
The inventory plugin community.general.iocage should provide the same functionality.
Warning
The inventory plugin community.general.iocage may differ from vbotka.freebsd.iocage. If you want be sure community.general.iocage provides the same functionality compare the hash from setup/vars/chcksum.yml with the community.general.iocage hash. Run the included playbook pb-iocage-obsolete.yml
shell> ansible-playbook pb-iocage-obsolete.yml
If the versions are different you’ll see a warning similar to this one
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
* WARNING *
* *
* The inventory plugins are different: *
* *
* vbotka.freebsd.iocage db8039e6 0.4.7 *
* community.general.iocage 3057fb18 10.2.0 *
* *
* Run the below commands and see the functionality provided *
* *
* shell> ansible-doc -t inventory vbotka.freebsd.iocage *
* shell> ansible-doc -t inventory community.general.iocage *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
The play shows nothing if the hashes match
shell> ANSIBLE_DISPLAY_OK_HOSTS=false \
ANSIBLE_DISPLAY_SKIPPED_HOSTS=false \
ansible-playbook pb-iocage-obsolete.yml
PLAY [Test inventory plugin version.] ****************************************
PLAY RECAP *******************************************************************
localhost: ok=3 changed=0 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0
Notes¶
Available in community.general >= 10.2.0
See
shell> ansible-doc -t inventory community.general.iocage
Configuration ansible.cfg¶
[defaults]
gathering = explicit
callback_result_format = yaml
[connection]
pipelining = true
Inventory hosts/01_iocage.yml¶
plugin: community.general.iocage
host: 10.1.0.18
user: admin
sudo: true
compose:
ansible_host: iocage_ip4 | split(',') | first
groups:
test_01: inventory_hostname.startswith('test')
Inventory hosts/02_iocage.yml¶
plugin: community.general.iocage
host: 10.1.0.73
user: admin
sudo: true
sudo_preserve_env: true
env:
CRYPTOGRAPHY_OPENSSL_NO_LEGACY: 1
compose:
ansible_host: iocage_ip4 | split(',') | first
groups:
test_02: inventory_hostname.startswith('test')
Inventory hosts/03_constructed.yml¶
plugin: ansible.builtin.constructed
groups:
test: inventory_hostname.startswith('test')
Playbook pb-test.yml¶
- hosts: test
tasks:
- debug:
var: iocage_ip4
- debug:
msg: |
{% for group in groups %}
{{ group }}: {{ groups[group] }}
{% endfor %}
run_once: true
Playbook output¶
(env) > ansible-playbook pb-test.yml -i hosts
PLAY [test] ***************************************************************************************
TASK [debug] **************************************************************************************
ok: [test_101] =>
iocage_ip4: 10.1.0.101
ok: [test_102] =>
iocage_ip4: 10.1.0.102
ok: [test_103] =>
iocage_ip4: 10.1.0.103
ok: [test_111] =>
iocage_ip4: 10.1.0.111
ok: [test_112] =>
iocage_ip4: 10.1.0.112
ok: [test_113] =>
iocage_ip4: 10.1.0.113
TASK [debug] **************************************************************************************
ok: [test_101] =>
msg: |-
all: ['ansible_client', 'test_101', 'test_102', 'test_103', 'test_111', 'test_112', 'test_113']
ungrouped: ['ansible_client']
test_01: ['test_101', 'test_102', 'test_103']
test_02: ['test_111', 'test_112', 'test_113']
test: ['test_101', 'test_102', 'test_103', 'test_111', 'test_112', 'test_113']
PLAY RECAP ****************************************************************************************
test_101: ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
test_102: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
test_103: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
test_111: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
test_112: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
test_113: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0