Last active
August 29, 2015 14:03
-
-
Save ravibhure/31e485096faa2b432c48 to your computer and use it in GitHub Desktop.
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 | |
# -*- coding: utf-8 -*- | |
# Just an example, how to create a ansible module ;) | |
from ansible.module_utils.basic import * | |
DOCUMENTATION = ''' | |
--- | |
module: public_key | |
short_description: Returns the SSH public key of the ansible ssh user | |
description: | |
- Finds the ansible user's ~/.ssh/id_rsa.pub and returns the value. | |
version_added: "1.5" | |
options: {} | |
notes: [] | |
requirements: [] | |
author: Chris Laskey | |
''' | |
EXAMPLES = ''' | |
# Example command-line invocation | |
ansible www.example.net -m public_key | |
''' | |
def main(): | |
module = AnsibleModule( | |
argument_spec = dict( | |
user = dict(required=True), | |
) | |
) | |
cmd = ["/bin/cat", "/home/ansible/.ssh/id_rsa.pub"] | |
rc, out, err = module.run_command(cmd, check_rc=True) | |
facts = { | |
'public_key': out | |
} | |
module.exit_json(changed=False, ansible_facts=facts) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment