Skip to content

Instantly share code, notes, and snippets.

@gondoi
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gondoi/9404864 to your computer and use it in GitHub Desktop.
Save gondoi/9404864 to your computer and use it in GitHub Desktop.
Simple script to get Ansible facts on localhost.
import json
from ansible.runner import Runner
from ansible import inventory
hosts = ['localhost']
inventory_manager = inventory.Inventory(hosts)
runner = Runner(
module_name='time',
#module_name='setup', # you can run this to get default system output
module_path='./temp',
transport='local',
pattern='localhost',
inventory=inventory_manager
)
print json.dumps(runner.run(), indent=True)
#!/usr/bin/python
import datetime
from ansible.module_utils.basic import *
module = AnsibleModule(
argument_spec = dict(
state = dict(default='present', choices=['present', 'absent']),
)
)
date = str(datetime.datetime.now())
module.exit_json(ansible_facts=dict(time=date))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment