facts gathering question

15 views
Skip to first unread message

Xander Cage

unread,
Oct 2, 2019, 3:39:30 AM10/2/19
to Ansible Development

hi all,

quick question, i'm trying to add some aix specific facts using the BaseFactCollector. for some reason the facts to not show up in the setup output. whats kind of wizardy has to be done do make this working?

i also added the new script to the following files.

facts/default_collectors.py:from ansible.module_utils.facts.system.aix import AIXFactCollector
facts/default_collectors.py:    AIXFactCollector


test code

from __future__ import (absolute_import, division, print_function)
__metaclass__
= type


import sys
import shlex
import os
import platform
import re
import itertools
import commands
import subprocess
try:
   
import json
except ImportError:
   
import simplejson as json


from ansible.module_utils.facts.utils import get_file_content


from ansible.module_utils.facts.collector import BaseFactCollector


class AIXFactCollector(BaseFactCollector):
   
"""
    Some handy AIX facts, more or less nice to haves
    """

    name
= 'aix_goodies'
    _fact_ids
= set()
    _platform
= 'AIX'


   
def get_oslevel(self):
       
"""
        get_oslevel function delivers oslevel -s output
        <OS Ver>-<TL>-<SP>-<BUILD DATE>
        OS Version, Technology Level, Servicepack and Build Date
        """

        rc
, out, err = module.run_command(["/usr/bin/oslevel", "-s"])
       
if rc != 0:
           
module.fail_json(msg="could not determine oslevel", rc=rc, err=err)
        oslevel
= {'oslevel_s': out.strip('\n')}
        keys
= ('OS_Ver', 'TL', 'SP', 'BUILD_DATE')
        values
= out.split('-')
        v_stript
= [v.rstrip('0\n') for v in values]
        adict
= dict(itertools.izip(keys, v_stript))
        oslevel
.update(adict)


       
return oslevel


ansible run

ansible all -i 'AIXBUILDHOSTNG,' -m setup -a 'gather_subset=aix_goodies' --tree /tmp/facts




Xander Cage

unread,
Oct 3, 2019, 8:03:32 AM10/3/19
to Ansible Development

nobody?

Brian Coca

unread,
Nov 11, 2019, 4:45:34 PM11/11/19
to Xander Cage, Ansible Development
defining the collector is not enough, you need to call it with all the
other collectors see 'default_collectors.py'


--
----------
Brian Coca

Reply all
Reply to author
Forward
0 new messages