diff --git a/changelogs/fragments/varnames-error-grammar.yml b/changelogs/fragments/varnames-error-grammar.yml new file mode 100644 index 00000000000..50edf2bdfb4 --- /dev/null +++ b/changelogs/fragments/varnames-error-grammar.yml @@ -0,0 +1,2 @@ +minor_changes: + - varnames lookup plugin - Fixed grammar error in exception message when the plugin is given a non-string term. diff --git a/lib/ansible/plugins/lookup/varnames.py b/lib/ansible/plugins/lookup/varnames.py index c786903dd8f..17c1789a651 100644 --- a/lib/ansible/plugins/lookup/varnames.py +++ b/lib/ansible/plugins/lookup/varnames.py @@ -66,7 +66,7 @@ class LookupModule(LookupBase): for term in terms: if not isinstance(term, string_types): - raise AnsibleError('Invalid setting identifier, "%s" is not a string, its a %s' % (term, type(term))) + raise AnsibleError('Invalid setting identifier, "%s" is not a string, it is a %s' % (term, type(term))) try: name = re.compile(term) diff --git a/test/integration/targets/lookup_varnames/aliases b/test/integration/targets/lookup_varnames/aliases new file mode 100644 index 00000000000..45489be80c6 --- /dev/null +++ b/test/integration/targets/lookup_varnames/aliases @@ -0,0 +1,2 @@ +shippable/posix/group2 +skip/python2.6 # lookups are controller only, and we no longer support Python 2.6 on the controller diff --git a/test/integration/targets/lookup_varnames/tasks/main.yml b/test/integration/targets/lookup_varnames/tasks/main.yml new file mode 100644 index 00000000000..fec3efd536f --- /dev/null +++ b/test/integration/targets/lookup_varnames/tasks/main.yml @@ -0,0 +1,38 @@ +# Example copied from docs +- name: Set some variables + set_fact: + qz_1: hello + qz_2: world + qa_1: "I won't show" + qz_: "I won't show either" + +- name: Try various regexes and make sure they work + assert: + that: + - lookup('varnames', '^qz_.+', wantlist=True) == ['qz_1', 'qz_2'] + - lookup('varnames', '^qz_.+', '^qa.*', wantlist=True) == ['qz_1', 'qz_2', 'qa_1'] + - "'ansible_python_interpreter' in lookup('varnames', '^ansible_.*', wantlist=True)" + - lookup('varnames', '^doesnotexist.*', wantlist=True) == [] + - lookup('varnames', '^doesnotexist.*', '.*python_inter.*', wantlist=True) == ['ansible_python_interpreter'] + - lookup('varnames', '^q.*_\d', wantlist=True) == ['qz_1', 'qz_2', 'qa_1'] + - lookup('varnames', '^q.*_\d') == 'qz_1,qz_2,qa_1' + +- name: Make sure it fails successfully + set_fact: + fail1: "{{ lookup('varnames', True, wantlist=True) }}" + register: fail1res + ignore_errors: yes + +- name: Make sure it fails successfully + set_fact: + fail2: "{{ lookup('varnames', '*', wantlist=True) }}" + register: fail2res + ignore_errors: yes + +- assert: + that: + - fail1res is failed + - "'Invalid setting identifier' in fail1res.msg" + - fail2res is failed + - "'Unable to use' in fail2res.msg" + - "'nothing to repeat' in fail2res.msg"