Skip to content

Ansible Custom Module svcs_attr_facts. athers facts about Solaris SMF attribute for a specific services by svcs.

License

Notifications You must be signed in to change notification settings

NomakCooper/svcs_attr_facts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ansible Custom Module Oracle Solaris python license

svcs_attr_facts ansible custom module

Gathers facts about Solaris SMF attribute for a specific services by svcs.

Description :

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

Repo files:

├── /library                
│   └── svcs_attr_facts.py   ##<-- python custom module
└── svcs_attr.yml            ##<-- ansible playbook example

Requirements :

  • This module supports SunOS/Oracle Solaris only
  • The SMF services info are gathered from the svcs command

Parameters :

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 )

Attributes :

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.

Examples :

Tasks

---
- 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."

'alias'_attr facts:

  "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)"
      }
    ]
  },

debug output from example :

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."
}

Returned Facts :

  • 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)"

SANITY TEST

  • Ansible sanity test is available in SANITY.md file

Integration

  1. 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
  1. 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

About

Ansible Custom Module svcs_attr_facts. athers facts about Solaris SMF attribute for a specific services by svcs.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages