Skip to content

Ansible Custom Module svcs_facts. Gathers facts about Solaris SMF services on a SunOS/Oracle Solaris host by svcs

License

Notifications You must be signed in to change notification settings

NomakCooper/svcs_facts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ansible Custom Module Oracle Solaris python license

svcs_facts ansible custom module

Gathers facts about Solaris SMF services on a SunOS/Oracle Solaris host by svcs

Description :

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

Repo files:

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

Requirements :

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

Parameters :

  • no parameters are needed

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

svcs_list facts:

"ansible_facts": {
    "svcs_list": [
      {
        "STATE": "disabled",
        "NSTATE": "-",
        "STIME": "21:21:57",
        "CTID": "67",
        "FMRI": "svc:/platform/i86pc/acpihpd:default"
      }
  ]
},

debug output from example :

TASK [print STATE of sendmail service] *****************************************
ok: [sol11host] => {
    "msg": "sendmail service is in online state from 21:22:06"
}

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

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_facts.py      ##<-- python custom module
│   │    └── your_playbook.yml      ##<-- you playbook

About

Ansible Custom Module svcs_facts. Gathers facts about Solaris SMF services on a SunOS/Oracle Solaris host by svcs

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages