Last active
August 29, 2015 13:57
-
-
Save gondoi/9404864 to your computer and use it in GitHub Desktop.
Simple script to get Ansible facts on localhost.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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