zoneadm_facts is a custom module for ansible that creates an ansible_facts containing the list and details of configured local zones on a SunOS/Oracle Solaris global zone
├── /library
│ └── zoneadm_facts.py ##<-- python custom module
└── zoneadm_list.yml ##<-- ansible playbook example
- This module supports SunOS/Oracle Solaris only
- The Local Zone info are gathered from the zoneadm command
- no parameters are needed
Attribute | Support | Description |
---|---|---|
check_mode | full | Can run in check_mode and return changed status prediction without modifying target. |
facts | full | Action returns an ansible_facts dictionary that will update existing host facts. |
---
# Gather local zone info
- name: Gather facts configured local zone
zoneadm_facts:
# print all lz name at running STATE
- name: Print all LZ at running STATE
debug:
msg: "{{ ansible_facts.zone_list | selectattr('STATUS','equalto', 'running' ) | map(attribute='NAME') }}"
# print lz STATUS by ID
- name: Print STATUS of LZ ID 3
debug:
msg: "LZ ID 3 STATUS : {{ ansible_facts.zone_list | selectattr('ID','equalto', '3' ) | map(attribute='STATUS') | first }}"
"ansible_facts": {
"zone_list": [
{
"STATUS": "running",
"NAME": "sol10lab",
"IP": "shared",
"BRAND": "solaris10",
"PATH": "/zones/sol10lab",
"ID": "3"
}
]
},
TASK [Print STATUS of LZ ID 3] *************************************************
ok: [global_zone_host] => {
"msg": "LZ ID 3 STATUS : running"
}
TASK [Print all LZ at running STATE] *******************************************
ok: [global_zone_host] => {
"msg": [
"sol9lab",
"sol10lab"
]
}
- Facts returned by this module are added/updated in the hostvars host facts and can be referenced by name just like any other host fact. They do not need to be registered in order to use them.
Key | Type | Description | Returned | Sample |
---|---|---|---|---|
zone_list | list / elements=string | Configured local Zone list | ||
ID | string | The local zone ID. | always | "10" |
NAME | string | The local zone name, could match the hostname of the local zone | always | "sol11lab" |
STATUS | string | The local zone status. running, installed, configured. | always | "running" |
PATH | string | The local zone path. | always | "/zones/sol11lab" |
BRAND | string | The local zone brand. native, solaris10 and more. | always | "native" |
IP | string | The local zone IP or shared. | always | "shared" |
- Ansible sanity test is available in SANITY.md file
- Assuming you are in the root folder of your ansible project.
Specify a module path in your ansible configuration file.
$ vim ansible.cfg
[defaults]
...
library = ./library
...
Create the directory and copy the python modules into that directory
$ mkdir library
$ cp path/to/module library
- If you use Ansible AWX and have no way to edit the control node, you can add the /library directory to the same directory as the playbook .yml file
├── root repository
│ ├── playbooks
│ │ ├── /library
│ │ │ └── zoneadm_facts.py ##<-- python custom module
│ │ └── your_playbook.yml ##<-- you playbook