summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/config
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/config')
-rw-r--r--test/integration/targets/config/aliases2
-rw-r--r--test/integration/targets/config/files/types.env11
-rw-r--r--test/integration/targets/config/files/types.ini13
-rw-r--r--test/integration/targets/config/files/types.vars15
-rw-r--r--test/integration/targets/config/files/types_dump.txt8
-rw-r--r--test/integration/targets/config/inline_comment_ansible.cfg2
-rw-r--r--test/integration/targets/config/lookup_plugins/bogus.py51
-rw-r--r--test/integration/targets/config/lookup_plugins/types.py82
-rwxr-xr-xtest/integration/targets/config/runme.sh43
-rw-r--r--test/integration/targets/config/type_munging.cfg8
-rw-r--r--test/integration/targets/config/types.yml25
-rw-r--r--test/integration/targets/config/validation.yml17
12 files changed, 277 insertions, 0 deletions
diff --git a/test/integration/targets/config/aliases b/test/integration/targets/config/aliases
new file mode 100644
index 0000000..8278ec8
--- /dev/null
+++ b/test/integration/targets/config/aliases
@@ -0,0 +1,2 @@
+shippable/posix/group3
+context/controller
diff --git a/test/integration/targets/config/files/types.env b/test/integration/targets/config/files/types.env
new file mode 100644
index 0000000..b5fc43e
--- /dev/null
+++ b/test/integration/targets/config/files/types.env
@@ -0,0 +1,11 @@
+# valid(list): does nothihng, just for testing values
+ANSIBLE_TYPES_VALID=
+
+# mustunquote(list): does nothihng, just for testing values
+ANSIBLE_TYPES_MUSTUNQUOTE=
+
+# notvalid(list): does nothihng, just for testing values
+ANSIBLE_TYPES_NOTVALID=
+
+# totallynotvalid(list): does nothihng, just for testing values
+ANSIBLE_TYPES_TOTALLYNOTVALID=
diff --git a/test/integration/targets/config/files/types.ini b/test/integration/targets/config/files/types.ini
new file mode 100644
index 0000000..c04b6d5
--- /dev/null
+++ b/test/integration/targets/config/files/types.ini
@@ -0,0 +1,13 @@
+[list_values]
+# (list) does nothihng, just for testing values
+mustunquote=
+
+# (list) does nothihng, just for testing values
+notvalid=
+
+# (list) does nothihng, just for testing values
+totallynotvalid=
+
+# (list) does nothihng, just for testing values
+valid=
+
diff --git a/test/integration/targets/config/files/types.vars b/test/integration/targets/config/files/types.vars
new file mode 100644
index 0000000..d1427fc
--- /dev/null
+++ b/test/integration/targets/config/files/types.vars
@@ -0,0 +1,15 @@
+# valid(list): does nothihng, just for testing values
+ansible_types_valid: ''
+
+
+# mustunquote(list): does nothihng, just for testing values
+ansible_types_mustunquote: ''
+
+
+# notvalid(list): does nothihng, just for testing values
+ansible_types_notvalid: ''
+
+
+# totallynotvalid(list): does nothihng, just for testing values
+ansible_types_totallynotvalid: ''
+
diff --git a/test/integration/targets/config/files/types_dump.txt b/test/integration/targets/config/files/types_dump.txt
new file mode 100644
index 0000000..2139f4d
--- /dev/null
+++ b/test/integration/targets/config/files/types_dump.txt
@@ -0,0 +1,8 @@
+
+types:
+_____
+_terms(default) = None
+mustunquote(default) = None
+notvalid(default) = None
+totallynotvalid(default) = None
+valid(default) = None
diff --git a/test/integration/targets/config/inline_comment_ansible.cfg b/test/integration/targets/config/inline_comment_ansible.cfg
new file mode 100644
index 0000000..01a95c4
--- /dev/null
+++ b/test/integration/targets/config/inline_comment_ansible.cfg
@@ -0,0 +1,2 @@
+[defaults]
+cowsay_enabled_stencils = ansibull ; BOOM
diff --git a/test/integration/targets/config/lookup_plugins/bogus.py b/test/integration/targets/config/lookup_plugins/bogus.py
new file mode 100644
index 0000000..34dc98a
--- /dev/null
+++ b/test/integration/targets/config/lookup_plugins/bogus.py
@@ -0,0 +1,51 @@
+# (c) 2021 Ansible Project
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+# Make coding more python3-ish
+from __future__ import (absolute_import, division, print_function)
+
+__metaclass__ = type
+
+DOCUMENTATION = """
+ name: bogus
+ author: Ansible Core Team
+ version_added: histerical
+ short_description: returns what you gave it
+ description:
+ - this is mostly a noop
+ options:
+ _terms:
+ description: stuff to pass through
+ test_list:
+ description: does nothihng, just for testing values
+ type: list
+ choices:
+ - Dan
+ - Yevgeni
+ - Carla
+ - Manuela
+"""
+
+EXAMPLES = """
+- name: like some other plugins, this is mostly useless
+ debug: msg={{ q('bogus', [1,2,3])}}
+"""
+
+RETURN = """
+ _list:
+ description: basically the same as you fed in
+ type: list
+ elements: raw
+"""
+
+from ansible.plugins.lookup import LookupBase
+
+
+class LookupModule(LookupBase):
+
+ def run(self, terms, variables=None, **kwargs):
+
+ self.set_options(var_options=variables, direct=kwargs)
+ dump = self.get_option('test_list')
+
+ return terms
diff --git a/test/integration/targets/config/lookup_plugins/types.py b/test/integration/targets/config/lookup_plugins/types.py
new file mode 100644
index 0000000..d309229
--- /dev/null
+++ b/test/integration/targets/config/lookup_plugins/types.py
@@ -0,0 +1,82 @@
+# (c) 2021 Ansible Project
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+# Make coding more python3-ish
+from __future__ import (absolute_import, division, print_function)
+
+__metaclass__ = type
+
+DOCUMENTATION = """
+ name: types
+ author: Ansible Core Team
+ version_added: histerical
+ short_description: returns what you gave it
+ description:
+ - this is mostly a noop
+ options:
+ _terms:
+ description: stuff to pass through
+ valid:
+ description: does nothihng, just for testing values
+ type: list
+ ini:
+ - section: list_values
+ key: valid
+ env:
+ - name: ANSIBLE_TYPES_VALID
+ vars:
+ - name: ansible_types_valid
+ mustunquote:
+ description: does nothihng, just for testing values
+ type: list
+ ini:
+ - section: list_values
+ key: mustunquote
+ env:
+ - name: ANSIBLE_TYPES_MUSTUNQUOTE
+ vars:
+ - name: ansible_types_mustunquote
+ notvalid:
+ description: does nothihng, just for testing values
+ type: list
+ ini:
+ - section: list_values
+ key: notvalid
+ env:
+ - name: ANSIBLE_TYPES_NOTVALID
+ vars:
+ - name: ansible_types_notvalid
+ totallynotvalid:
+ description: does nothihng, just for testing values
+ type: list
+ ini:
+ - section: list_values
+ key: totallynotvalid
+ env:
+ - name: ANSIBLE_TYPES_TOTALLYNOTVALID
+ vars:
+ - name: ansible_types_totallynotvalid
+"""
+
+EXAMPLES = """
+- name: like some other plugins, this is mostly useless
+ debug: msg={{ q('types', [1,2,3])}}
+"""
+
+RETURN = """
+ _list:
+ description: basically the same as you fed in
+ type: list
+ elements: raw
+"""
+
+from ansible.plugins.lookup import LookupBase
+
+
+class LookupModule(LookupBase):
+
+ def run(self, terms, variables=None, **kwargs):
+
+ self.set_options(var_options=variables, direct=kwargs)
+
+ return terms
diff --git a/test/integration/targets/config/runme.sh b/test/integration/targets/config/runme.sh
new file mode 100755
index 0000000..122e15d
--- /dev/null
+++ b/test/integration/targets/config/runme.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+
+set -eux
+
+# ignore empty env var and use default
+# shellcheck disable=SC1007
+ANSIBLE_TIMEOUT= ansible -m ping testhost -i ../../inventory "$@"
+
+# env var is wrong type, this should be a fatal error pointing at the setting
+ANSIBLE_TIMEOUT='lola' ansible -m ping testhost -i ../../inventory "$@" 2>&1|grep 'Invalid type for configuration option setting: DEFAULT_TIMEOUT (from env: ANSIBLE_TIMEOUT)'
+
+# https://github.com/ansible/ansible/issues/69577
+ANSIBLE_REMOTE_TMP="$HOME/.ansible/directory_with_no_space" ansible -m ping testhost -i ../../inventory "$@"
+
+ANSIBLE_REMOTE_TMP="$HOME/.ansible/directory with space" ansible -m ping testhost -i ../../inventory "$@"
+
+ANSIBLE_CONFIG=nonexistent.cfg ansible-config dump --only-changed -v | grep 'No config file found; using defaults'
+
+# https://github.com/ansible/ansible/pull/73715
+ANSIBLE_CONFIG=inline_comment_ansible.cfg ansible-config dump --only-changed | grep "'ansibull'"
+
+# test type headers are only displayed with --only-changed -t all for changed options
+env -i PATH="$PATH" PYTHONPATH="$PYTHONPATH" ansible-config dump --only-changed -t all | grep -v "CONNECTION"
+env -i PATH="$PATH" PYTHONPATH="$PYTHONPATH" ANSIBLE_SSH_PIPELINING=True ansible-config dump --only-changed -t all | grep "CONNECTION"
+
+# test the config option validation
+ansible-playbook validation.yml "$@"
+
+# test types from config (just lists for now)
+ANSIBLE_CONFIG=type_munging.cfg ansible-playbook types.yml "$@"
+
+cleanup() {
+ rm -f files/*.new.*
+}
+
+trap 'cleanup' EXIT
+
+# check a-c init per format
+for format in "vars" "ini" "env"
+do
+ ANSIBLE_LOOKUP_PLUGINS=./ ansible-config init types -t lookup -f "${format}" > "files/types.new.${format}"
+ diff -u "files/types.${format}" "files/types.new.${format}"
+done
diff --git a/test/integration/targets/config/type_munging.cfg b/test/integration/targets/config/type_munging.cfg
new file mode 100644
index 0000000..d6aeaab
--- /dev/null
+++ b/test/integration/targets/config/type_munging.cfg
@@ -0,0 +1,8 @@
+[defaults]
+nothing = here
+
+[list_values]
+valid = 1, 2, 3
+mustunquote = '1', '2', '3'
+notvalid = [1, 2, 3]
+totallynotvalid = ['1', '2', '3']
diff --git a/test/integration/targets/config/types.yml b/test/integration/targets/config/types.yml
new file mode 100644
index 0000000..650a96f
--- /dev/null
+++ b/test/integration/targets/config/types.yml
@@ -0,0 +1,25 @@
+- hosts: localhost
+ gather_facts: false
+ tasks:
+ - name: ensures we got the list we expected
+ block:
+ - name: initialize plugin
+ debug: msg={{ lookup('types', 'starting test') }}
+
+ - set_fact:
+ valid: '{{ lookup("config", "valid", plugin_type="lookup", plugin_name="types") }}'
+ mustunquote: '{{ lookup("config", "mustunquote", plugin_type="lookup", plugin_name="types") }}'
+ notvalid: '{{ lookup("config", "notvalid", plugin_type="lookup", plugin_name="types") }}'
+ totallynotvalid: '{{ lookup("config", "totallynotvalid", plugin_type="lookup", plugin_name="types") }}'
+
+ - assert:
+ that:
+ - 'valid|type_debug == "list"'
+ - 'mustunquote|type_debug == "list"'
+ - 'notvalid|type_debug == "list"'
+ - 'totallynotvalid|type_debug == "list"'
+ - valid[0]|int == 1
+ - mustunquote[0]|int == 1
+ - "notvalid[0] == '[1'"
+ # using 'and true' to avoid quote hell
+ - totallynotvalid[0] == "['1'" and True
diff --git a/test/integration/targets/config/validation.yml b/test/integration/targets/config/validation.yml
new file mode 100644
index 0000000..1c81e66
--- /dev/null
+++ b/test/integration/targets/config/validation.yml
@@ -0,0 +1,17 @@
+- hosts: localhost
+ gather_facts: false
+ tasks:
+ - name: does nothing but an empty assign, should fail only if lookup gets invalid options
+ set_fact: whatever={{ lookup('bogus', 1, test_list=['Dan', 'Manuela']) }}
+
+ - name: now pass invalid option and fail!
+ set_fact: whatever={{ lookup('bogus', 1, test_list=['Dan', 'Manuela', 'Yoko']) }}
+ register: bad_input
+ ignore_errors: true
+
+ - name: ensure it fails as expected
+ assert:
+ that:
+ - bad_input is failed
+ - '"Invalid value " in bad_input.msg'
+ - '"valid values are:" in bad_input.msg'