Skip to content

Instantly share code, notes, and snippets.

@ravibhure
Last active August 29, 2015 14:03
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 ravibhure/31e485096faa2b432c48 to your computer and use it in GitHub Desktop.
Save ravibhure/31e485096faa2b432c48 to your computer and use it in GitHub Desktop.
#!/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