svcs_attr_facts is a custom module for ansible that creates an ansible_facts containing the attribute list of specific SMF services on a SunOS/Oracle Solaris host
├── /library
│ └── svcs_attr_facts.py ##<-- python custom module
└── svcs_attr.yml ##<-- ansible playbook example
- This module supports SunOS/Oracle Solaris only
- The SMF services info are gathered from the svcs command
Parameter | Type | Required | Sample | Comment |
---|---|---|---|---|
fmri | string | True | "svc:/network/smtp:sendmail" | The FMRI of the service instance |
alias | string | True | "sendmail" | Service alias, a name of your choice which will then be automatically assigned to the dict object name ( sendmail_attr ) |
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 attribute of sendmail fmri
svcs_attr_facts:
fmri: "svc:/network/smtp:sendmail"
alias: sendmail
- name: set fact for print
set_fact:
sendmail_state: "{{ ansible_facts.sendmail_attr| map(attribute='state') | first }}"
sendmail_logfile: "{{ ansible_facts.sendmail_attr| map(attribute='logfile') | first }}"
- name: print state and logfile attribute of sendmail service
debug:
msg: "sendmail service is {{sendmail_state}}. Check logfile {{sendmail_logfile}} for info."
"ansible_facts": {
"sendmail_attr": [
{
"fmri": "svc:/network/smtp:sendmail",
"name": "sendmail SMTP mail transfer agent",
"enabled": "true",
"state": "online",
"next_state": "none",
"state_time": "August 1, 2024 at 6:34:29 PM CEST",
"logfile": "/var/svc/log/network-smtp:sendmail.log",
"restarter": "svc:/system/svc/restarter:default",
"contract_id": "133 ",
"manifest": "/lib/svc/manifest/network/smtp-sendmail.xml",
"dependency1": "optional_all/none svc:/system/filesystem/autofs (online)",
"dependency2": "require_all/refresh file://localhost/etc/mail/sendmail.cf (online)",
"dependency3": "require_all/refresh file://localhost/etc/nsswitch.conf (online)",
"dependency4": "require_all/none svc:/system/filesystem/local (online)",
"dependency5": "optional_all/refresh svc:/system/identity:domain (online)",
"dependency6": "require_all/refresh svc:/milestone/name-services (online)",
"dependency7": "require_all/none svc:/network/service (online)",
"dependency8": "optional_all/none svc:/system/system-log (multiple)"
}
]
},
TASK [print state and logfile attribute of sendmail service] *****************************************
ok: [sol11host] => {
"msg": "sendmail service is online. Check logfile /var/svc/log/network-smtp:sendmail.log for info."
}
- 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.
- Attributes change according to the service selected
Key | Type | Description | Returned | Sample |
---|---|---|---|---|
'alias'_attr | list / elements=string | SMF Service attribute list | ||
fmri | string | The FMRI of the service instance. | always | "svc:/network/smtp:sendmail" |
name | string | The complite name of service. | always | "sendmail SMTP mail transfer agent" |
enabled | string | If the service instance is enabled or disabled. | always | "true" |
state | string | The current state of service instance. | always | "online" |
next_state | string | The next state of the service. | always | "none" |
state_time | string | Date and time of the last transaction of the current status. | always | "August 1, 2024 at 6:34:29 PM CEST" |
logfile | string | The log file of service instance. | always | "/var/svc/log/network-smtp:sendmail.log" |
restarter | string | The master restarter daemon for SMF. | always | "svc:/system/svc/restarter:default" |
contract_id | string | The primary contract ID for the service instance. | always | "133 " |
manifest | string | The .xml manifest file of the service instance. | always | "/lib/svc/manifest/network/smtp-sendmail.xml" |
dependency(n) | string | The dependency service. ( the number of dependencies changes according to the service ) | always | "optional_all/none svc:/system/filesystem/autofs (online)" |
- 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_attr_facts.py ##<-- python custom module
│ │ └── your_playbook.yml ##<-- you playbook