svcs_facts is a custom module for ansible that creates an ansible_facts containing the list and details of SMF services on a SunOS/Oracle Solaris host
├── /library
│ └── svcs_facts.py ##<-- python custom module
└── svcs_list.yml ##<-- ansible playbook example
- This module supports SunOS/Oracle Solaris only
- The SMF services info are gathered from the svcs 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. |
---
- name: Gather facts SMF service
svcs_facts:
- name: set fact for debug
set_fact:
sendmail_state: "{{ ansible_facts.svcs_list | selectattr('FMRI','equalto', 'svc:/network/smtp:sendmail' ) | map(attribute='STATE') | first }}"
sendmail_stime: "{{ ansible_facts.svcs_list | selectattr('FMRI','equalto', 'svc:/network/smtp:sendmail' ) | map(attribute='STIME') | first }}"
- name: print STATE of sendmail service
debug:
msg: "sendmail service is in {{sendmail_state}} state from {{sendmail_stime}}"
"ansible_facts": {
"svcs_list": [
{
"STATE": "disabled",
"NSTATE": "-",
"STIME": "21:21:57",
"CTID": "67",
"FMRI": "svc:/platform/i86pc/acpihpd:default"
}
]
},
TASK [print STATE of sendmail service] *****************************************
ok: [sol11host] => {
"msg": "sendmail service is in online state from 21:22:06"
}
- 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 |
---|---|---|---|---|
svcs_list | list / elements=string | SMF Services list | ||
STATE | string | The state of the service instance. | always | "online" |
NSTATE | string | The next state of the service. | always | "-" |
STIME | string | If the service instance entered the current state within the last 24 hours, this value indicates the time that it did so. Otherwise, this value indicates the date on which it did so, printed with underscores (_) in place of blanks. | always | "21:21:47" |
CTID | string | The primary contract ID for the service instance. Not all instances have valid primary contract IDs. | always | "67" |
FMRI | string | The FMRI of the service instance. | always | "svc:/network/smtp:sendmail" |
- 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
│ │ │ └── svcs_facts.py ##<-- python custom module
│ │ └── your_playbook.yml ##<-- you playbook