Skip to content

Instantly share code, notes, and snippets.

@gondoi
Last active Aug 29, 2015
Embed
What would you like to do?
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