Created
August 4, 2014 15:13
-
-
Save christophebiocca/a5360cb46a994bd59695 to your computer and use it in GitHub Desktop.
dhparam module
This file contains 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/python2 | |
import os.path | |
import re | |
bit_matcher = re.compile(r'PKCS#3 DH Parameters: \((\d+) bit\)',re.MULTILINE) | |
def main(): | |
module = AnsibleModule( | |
supports_check_mode=True, | |
argument_spec = { | |
'size': {'default':'512', 'choices':[str(2**x) for x in range(9,13)]}, | |
'path': {'required':True}, | |
} | |
) | |
size = module.params['size'] | |
output_file = module.params['path'] | |
openssl_path = module.get_bin_path('openssl', True) | |
need_to_modify = True | |
before=None | |
if os.path.exists(output_file): | |
# Check that it's the right size. | |
(rc,stdout,stderr) = module.run_command( | |
[openssl_path,'dhparam','-in',output_file,'-text','-noout'], | |
check_rc=True, | |
) | |
match = bit_matcher.search(stdout) | |
if match: | |
before = match.group(1) | |
need_to_modify = before != size | |
if not need_to_modify: | |
module.exit_json(changed=False, size=size) | |
if not module.check_mode: | |
module.run_command( | |
[openssl_path,'dhparam',size,'-out',output_file], | |
check_rc=True, | |
) | |
module.exit_json(changed=True, before=before, after=size) | |
from ansible.module_utils.basic import * | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment