| 1 |
.. |
| 2 |
Copyright (c) Ansible Project |
| 3 |
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
.. _ansible_collections.community.general.docsite.guide_iocage.guide_iocage_inventory.guide_iocage_inventory_aliases: |
| 7 |
|
| 8 |
Aliases |
| 9 |
------- |
| 10 |
|
| 11 |
Quoting :ref:`inventory_aliases`: |
| 12 |
|
| 13 |
The ``inventory_hostname`` is the unique identifier for a host in Ansible, this can be an IP or a hostname, but also just an 'alias' or short name for the host. |
| 14 |
|
| 15 |
As root at the iocage host, stop and destroy all jails: |
| 16 |
|
| 17 |
.. code-block:: console |
| 18 |
|
| 19 |
shell> iocage stop ALL |
| 20 |
* Stopping srv_1 |
| 21 |
+ Executing prestop OK |
| 22 |
+ Stopping services OK |
| 23 |
+ Tearing down VNET OK |
| 24 |
+ Removing devfs_ruleset: 1000 OK |
| 25 |
+ Removing jail process OK |
| 26 |
+ Executing poststop OK |
| 27 |
* Stopping srv_2 |
| 28 |
+ Executing prestop OK |
| 29 |
+ Stopping services OK |
| 30 |
+ Tearing down VNET OK |
| 31 |
+ Removing devfs_ruleset: 1001 OK |
| 32 |
+ Removing jail process OK |
| 33 |
+ Executing poststop OK |
| 34 |
* Stopping srv_3 |
| 35 |
+ Executing prestop OK |
| 36 |
+ Stopping services OK |
| 37 |
+ Tearing down VNET OK |
| 38 |
+ Removing devfs_ruleset: 1002 OK |
| 39 |
+ Removing jail process OK |
| 40 |
+ Executing poststop OK |
| 41 |
ansible_client is not running! |
| 42 |
|
| 43 |
shell> iocage destroy -f srv_1 srv_2 srv_3 |
| 44 |
Destroying srv_1 |
| 45 |
Destroying srv_2 |
| 46 |
Destroying srv_3 |
| 47 |
|
| 48 |
Create three VNET jails with a DHCP interface from the template *ansible_client*. Use the option ``--count``: |
| 49 |
|
| 50 |
.. code-block:: console |
| 51 |
|
| 52 |
shell> iocage create --short --template ansible_client --count 3 bpf=1 dhcp=1 vnet=1 |
| 53 |
1c11de2d successfully created! |
| 54 |
9d94cc9e successfully created! |
| 55 |
052b9557 successfully created! |
| 56 |
|
| 57 |
The names are random. Start the jails: |
| 58 |
|
| 59 |
.. code-block:: console |
| 60 |
|
| 61 |
shell> iocage start ALL |
| 62 |
No default gateway found for ipv6. |
| 63 |
* Starting 052b9557 |
| 64 |
+ Started OK |
| 65 |
+ Using devfs_ruleset: 1000 (iocage generated default) |
| 66 |
+ Configuring VNET OK |
| 67 |
+ Using IP options: vnet |
| 68 |
+ Starting services OK |
| 69 |
+ Executing poststart OK |
| 70 |
+ DHCP Address: 10.1.0.137/24 |
| 71 |
No default gateway found for ipv6. |
| 72 |
* Starting 1c11de2d |
| 73 |
+ Started OK |
| 74 |
+ Using devfs_ruleset: 1001 (iocage generated default) |
| 75 |
+ Configuring VNET OK |
| 76 |
+ Using IP options: vnet |
| 77 |
+ Starting services OK |
| 78 |
+ Executing poststart OK |
| 79 |
+ DHCP Address: 10.1.0.146/24 |
| 80 |
No default gateway found for ipv6. |
| 81 |
* Starting 9d94cc9e |
| 82 |
+ Started OK |
| 83 |
+ Using devfs_ruleset: 1002 (iocage generated default) |
| 84 |
+ Configuring VNET OK |
| 85 |
+ Using IP options: vnet |
| 86 |
+ Starting services OK |
| 87 |
+ Executing poststart OK |
| 88 |
+ DHCP Address: 10.1.0.115/24 |
| 89 |
Please convert back to a jail before trying to start ansible_client |
| 90 |
|
| 91 |
List the jails: |
| 92 |
|
| 93 |
.. code-block:: console |
| 94 |
|
| 95 |
shell> iocage list -l |
| 96 |
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+ |
| 97 |
| JID | NAME | BOOT | STATE | TYPE | RELEASE | IP4 | IP6 | TEMPLATE | BASEJAIL | |
| 98 |
+=====+==========+======+=======+======+=================+====================+=====+================+==========+ |
| 99 |
| 207 | 052b9557 | off | up | jail | 14.2-RELEASE-p3 | epair0b|10.1.0.137 | - | ansible_client | no | |
| 100 |
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+ |
| 101 |
| 208 | 1c11de2d | off | up | jail | 14.2-RELEASE-p3 | epair0b|10.1.0.146 | - | ansible_client | no | |
| 102 |
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+ |
| 103 |
| 209 | 9d94cc9e | off | up | jail | 14.2-RELEASE-p3 | epair0b|10.1.0.115 | - | ansible_client | no | |
| 104 |
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+ |
| 105 |
|
| 106 |
Set notes. The tag *alias* will be used to create inventory aliases: |
| 107 |
|
| 108 |
.. code-block:: console |
| 109 |
|
| 110 |
shell> iocage set notes="vmm=iocage_02 project=foo alias=srv_1" 052b9557 |
| 111 |
notes: none -> vmm=iocage_02 project=foo alias=srv_1 |
| 112 |
shell> iocage set notes="vmm=iocage_02 project=foo alias=srv_2" 1c11de2d |
| 113 |
notes: none -> vmm=iocage_02 project=foo alias=srv_2 |
| 114 |
shell> iocage set notes="vmm=iocage_02 project=bar alias=srv_3" 9d94cc9e |
| 115 |
notes: none -> vmm=iocage_02 project=bar alias=srv_3 |
| 116 |
|
| 117 |
Update the inventory configuration. Set the option |
| 118 |
:ansopt:`community.general.iocage#inventory:inventory_hostname_tag` to :ansval:`alias`. This tag keeps the |
| 119 |
value of the alias. The option :ansopt:`community.general.iocage#inventory:get_properties` must be |
| 120 |
enabled. For example, ``hosts/02_iocage.yml`` contains: |
| 121 |
|
| 122 |
.. code-block:: yaml |
| 123 |
|
| 124 |
plugin: community.general.iocage |
| 125 |
host: 10.1.0.73 |
| 126 |
user: admin |
| 127 |
get_properties: true |
| 128 |
inventory_hostname_tag: alias |
| 129 |
hooks_results: |
| 130 |
- /var/db/dhclient-hook.address.epair0b |
| 131 |
compose: |
| 132 |
ansible_host: (iocage_hooks.0 == '-') | ternary(iocage_ip4, iocage_hooks.0) |
| 133 |
iocage_tags: dict(iocage_properties.notes | split | map('split', '=')) |
| 134 |
keyed_groups: |
| 135 |
- prefix: vmm |
| 136 |
key: iocage_tags.vmm |
| 137 |
- prefix: project |
| 138 |
key: iocage_tags.project |
| 139 |
|
| 140 |
Display tags and groups. Create a playbook ``pb-test-groups.yml`` with the following content: |
| 141 |
|
| 142 |
.. code-block:: yaml+jinja |
| 143 |
|
| 144 |
- hosts: all |
| 145 |
remote_user: admin |
| 146 |
|
| 147 |
vars: |
| 148 |
|
| 149 |
ansible_python_interpreter: auto_silent |
| 150 |
|
| 151 |
tasks: |
| 152 |
|
| 153 |
- debug: |
| 154 |
var: iocage_tags |
| 155 |
|
| 156 |
- debug: |
| 157 |
msg: | |
| 158 |
{% for group in groups %} |
| 159 |
{{ group }}: {{ groups[group] }} |
| 160 |
{% endfor %} |
| 161 |
run_once: true |
| 162 |
|
| 163 |
Run the playbook: |
| 164 |
|
| 165 |
.. code-block:: console |
| 166 |
|
| 167 |
shell> ansible-playbook -i hosts/02_iocage.yml pb-test-groups.yml |
| 168 |
|
| 169 |
PLAY [all] ********************************************************************************************************** |
| 170 |
|
| 171 |
TASK [debug] ******************************************************************************************************** |
| 172 |
ok: [srv_1] => |
| 173 |
iocage_tags: |
| 174 |
alias: srv_1 |
| 175 |
project: foo |
| 176 |
vmm: iocage_02 |
| 177 |
ok: [srv_2] => |
| 178 |
iocage_tags: |
| 179 |
alias: srv_2 |
| 180 |
project: foo |
| 181 |
vmm: iocage_02 |
| 182 |
ok: [srv_3] => |
| 183 |
iocage_tags: |
| 184 |
alias: srv_3 |
| 185 |
project: bar |
| 186 |
vmm: iocage_02 |
| 187 |
|
| 188 |
TASK [debug] ******************************************************************************************************** |
| 189 |
ok: [srv_1] => |
| 190 |
msg: |- |
| 191 |
all: ['srv_1', 'srv_2', 'srv_3'] |
| 192 |
ungrouped: [] |
| 193 |
vmm_iocage_02: ['srv_1', 'srv_2', 'srv_3'] |
| 194 |
project_foo: ['srv_1', 'srv_2'] |
| 195 |
project_bar: ['srv_3'] |
| 196 |
|
| 197 |
PLAY RECAP ********************************************************************************************************** |
| 198 |
srv_1 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 |
| 199 |
srv_2 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 |
| 200 |
srv_3 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 |