diff options
Diffstat (limited to '')
4 files changed, 115 insertions, 0 deletions
diff --git a/test/integration/targets/gathering_facts/library/bogus_facts b/test/integration/targets/gathering_facts/library/bogus_facts new file mode 100644 index 0000000..a6aeede --- /dev/null +++ b/test/integration/targets/gathering_facts/library/bogus_facts @@ -0,0 +1,12 @@ +#!/bin/sh + +echo '{ + "changed": false, + "ansible_facts": { + "ansible_facts": { + "discovered_interpreter_python": "(touch /tmp/pwned-$(date -Iseconds)-$(whoami) ) 2>/dev/null >/dev/null && /usr/bin/python", + "bogus_overwrite": "yes" + }, + "dansible_iscovered_interpreter_python": "(touch /tmp/pwned-$(date -Iseconds)-$(whoami) ) 2>/dev/null >/dev/null && /usr/bin/python" + } +}' diff --git a/test/integration/targets/gathering_facts/library/facts_one b/test/integration/targets/gathering_facts/library/facts_one new file mode 100644 index 0000000..c74ab9a --- /dev/null +++ b/test/integration/targets/gathering_facts/library/facts_one @@ -0,0 +1,25 @@ +#!/bin/sh + +echo '{ + "changed": false, + "ansible_facts": { + "factsone": "from facts_one module", + "common_fact": "also from facts_one module", + "common_dict_fact": { + "key_one": "from facts_one", + "key_two": "from facts_one" + }, + "common_list_fact": [ + "one", + "three", + "five" + ], + "common_list_fact2": [ + "one", + "two", + "three", + "five", + "five" + ] + } +}' diff --git a/test/integration/targets/gathering_facts/library/facts_two b/test/integration/targets/gathering_facts/library/facts_two new file mode 100644 index 0000000..4e7c668 --- /dev/null +++ b/test/integration/targets/gathering_facts/library/facts_two @@ -0,0 +1,24 @@ +#!/bin/sh + +echo '{ + "changed": false, + "ansible_facts": { + "factstwo": "from facts_two module", + "common_fact": "also from facts_two module", + "common_dict_fact": { + "key_two": "from facts_two", + "key_four": "from facts_two" + }, + "common_list_fact": [ + "one", + "two", + "four" + ], + "common_list_fact2": [ + "one", + "two", + "four", + "four" + ] + } +}' diff --git a/test/integration/targets/gathering_facts/library/file_utils.py b/test/integration/targets/gathering_facts/library/file_utils.py new file mode 100644 index 0000000..5853802 --- /dev/null +++ b/test/integration/targets/gathering_facts/library/file_utils.py @@ -0,0 +1,54 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import json +import sys + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.facts.utils import ( + get_file_content, + get_file_lines, + get_mount_size, +) + + +def main(): + module = AnsibleModule( + argument_spec=dict( + test=dict(type='str', default='strip'), + touch_file=dict(type='str', default='/dev/null'), + line_sep_file=dict(type='str', default='/dev/null'), + line_sep_sep=dict(type='str', default='\n'), + ) + ) + + test = module.params['test'] + facts = {} + + if test == 'strip': + etc_passwd = get_file_content('/etc/passwd') + etc_passwd_unstripped = get_file_content('/etc/passwd', strip=False) + facts['etc_passwd_newlines'] = etc_passwd.count('\n') + facts['etc_passwd_newlines_unstripped'] = etc_passwd_unstripped.count('\n') + + elif test == 'default': + path = module.params['touch_file'] + facts['touch_default'] = get_file_content(path, default='i am a default') + + elif test == 'line_sep': + path = module.params['line_sep_file'] + sep = module.params['line_sep_sep'] + facts['line_sep'] = get_file_lines(path, line_sep=sep) + + elif test == 'invalid_mountpoint': + facts['invalid_mountpoint'] = get_mount_size('/doesnotexist') + + result = { + 'changed': False, + 'ansible_facts': facts, + } + + module.exit_json(**result) + + +main() |