summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/lookup_ini
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/lookup_ini')
-rw-r--r--test/integration/targets/lookup_ini/aliases1
-rw-r--r--test/integration/targets/lookup_ini/duplicate.ini3
-rw-r--r--test/integration/targets/lookup_ini/duplicate_case_check.ini3
-rw-r--r--test/integration/targets/lookup_ini/inventory2
-rw-r--r--test/integration/targets/lookup_ini/lookup-8859-15.ini7
-rw-r--r--test/integration/targets/lookup_ini/lookup.ini25
-rw-r--r--test/integration/targets/lookup_ini/lookup.properties6
-rw-r--r--test/integration/targets/lookup_ini/lookup_case_check.properties2
-rw-r--r--test/integration/targets/lookup_ini/mysql.ini8
-rwxr-xr-xtest/integration/targets/lookup_ini/runme.sh5
-rw-r--r--test/integration/targets/lookup_ini/test_allow_no_value.yml23
-rw-r--r--test/integration/targets/lookup_ini/test_case_sensitive.yml31
-rw-r--r--test/integration/targets/lookup_ini/test_errors.yml62
-rw-r--r--test/integration/targets/lookup_ini/test_ini.yml4
-rw-r--r--test/integration/targets/lookup_ini/test_lookup_properties.yml88
15 files changed, 270 insertions, 0 deletions
diff --git a/test/integration/targets/lookup_ini/aliases b/test/integration/targets/lookup_ini/aliases
new file mode 100644
index 0000000..70a7b7a
--- /dev/null
+++ b/test/integration/targets/lookup_ini/aliases
@@ -0,0 +1 @@
+shippable/posix/group5
diff --git a/test/integration/targets/lookup_ini/duplicate.ini b/test/integration/targets/lookup_ini/duplicate.ini
new file mode 100644
index 0000000..db510dd
--- /dev/null
+++ b/test/integration/targets/lookup_ini/duplicate.ini
@@ -0,0 +1,3 @@
+[reggae]
+name = bob
+name = marley
diff --git a/test/integration/targets/lookup_ini/duplicate_case_check.ini b/test/integration/targets/lookup_ini/duplicate_case_check.ini
new file mode 100644
index 0000000..abb0128
--- /dev/null
+++ b/test/integration/targets/lookup_ini/duplicate_case_check.ini
@@ -0,0 +1,3 @@
+[reggae]
+name = bob
+NAME = marley
diff --git a/test/integration/targets/lookup_ini/inventory b/test/integration/targets/lookup_ini/inventory
new file mode 100644
index 0000000..ae76427
--- /dev/null
+++ b/test/integration/targets/lookup_ini/inventory
@@ -0,0 +1,2 @@
+[all]
+testhost ansible_connection=local ansible_python_interpreter="{{ ansible_playbook_python }}"
diff --git a/test/integration/targets/lookup_ini/lookup-8859-15.ini b/test/integration/targets/lookup_ini/lookup-8859-15.ini
new file mode 100644
index 0000000..33f9c29
--- /dev/null
+++ b/test/integration/targets/lookup_ini/lookup-8859-15.ini
@@ -0,0 +1,7 @@
+[global]
+# A comment
+value1=Text associated with value1 and global section
+value2=Same for value2 and global section
+value.dot=Properties with dot
+field.with.space = another space
+field_with_unicode=été indien où à château français ïîôû
diff --git a/test/integration/targets/lookup_ini/lookup.ini b/test/integration/targets/lookup_ini/lookup.ini
new file mode 100644
index 0000000..5b7cc34
--- /dev/null
+++ b/test/integration/targets/lookup_ini/lookup.ini
@@ -0,0 +1,25 @@
+[global]
+# A comment
+value1=Text associated with value1 and global section
+value2=Same for value2 and global section
+value.dot=Properties with dot
+field.with.space = another space
+unicode=été indien où à château français ïîôû
+
+[section1]
+value1=section1/value1
+value2=section1/value2
+
+[value_section]
+value1=1
+value2=2
+value3=3
+other1=4
+other2=5
+
+[other_section]
+value1=1
+value2=2
+value3=3
+other1=4
+other2=5
diff --git a/test/integration/targets/lookup_ini/lookup.properties b/test/integration/targets/lookup_ini/lookup.properties
new file mode 100644
index 0000000..d71ce12
--- /dev/null
+++ b/test/integration/targets/lookup_ini/lookup.properties
@@ -0,0 +1,6 @@
+# A comment
+value1=Text associated with value1
+value2=Same for value2
+value.dot=Properties with dot
+field.with.space = another space
+field.with.unicode = été indien où à château français ïîôû
diff --git a/test/integration/targets/lookup_ini/lookup_case_check.properties b/test/integration/targets/lookup_ini/lookup_case_check.properties
new file mode 100644
index 0000000..ed3faaf
--- /dev/null
+++ b/test/integration/targets/lookup_ini/lookup_case_check.properties
@@ -0,0 +1,2 @@
+name = captain
+NAME = fantastic
diff --git a/test/integration/targets/lookup_ini/mysql.ini b/test/integration/targets/lookup_ini/mysql.ini
new file mode 100644
index 0000000..fa62d87
--- /dev/null
+++ b/test/integration/targets/lookup_ini/mysql.ini
@@ -0,0 +1,8 @@
+[mysqld]
+user = mysql
+pid-file = /var/run/mysqld/mysqld.pid
+skip-external-locking
+old_passwords = 1
+skip-bdb
+# we don't need ACID today
+skip-innodb
diff --git a/test/integration/targets/lookup_ini/runme.sh b/test/integration/targets/lookup_ini/runme.sh
new file mode 100755
index 0000000..6f44332
--- /dev/null
+++ b/test/integration/targets/lookup_ini/runme.sh
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+
+set -eux
+
+ansible-playbook test_ini.yml -i inventory -v "$@"
diff --git a/test/integration/targets/lookup_ini/test_allow_no_value.yml b/test/integration/targets/lookup_ini/test_allow_no_value.yml
new file mode 100644
index 0000000..bfdc376
--- /dev/null
+++ b/test/integration/targets/lookup_ini/test_allow_no_value.yml
@@ -0,0 +1,23 @@
+- name: Lookup test
+ hosts: testhost
+ tasks:
+ - name: "Read mysql.ini allow_none=False (default)"
+ set_fact:
+ test1: "{{ lookup('ini', 'user', file='mysql.ini', section='mysqld') }}"
+ register: result
+ ignore_errors: true
+
+ - name: "Read mysql.ini allow_no_value=True"
+ set_fact:
+ test2: "{{ lookup('ini', 'user', file='mysql.ini', section='mysqld', allow_no_value=True) }}"
+
+ - name: "Read mysql.ini allow_none=True"
+ set_fact:
+ test3: "{{ lookup('ini', 'skip-innodb', file='mysql.ini', section='mysqld', allow_none=True) }}"
+
+ - assert:
+ that:
+ - result is failed
+ - test2 == 'mysql'
+ - test3 == []
+ - test3|length == 0
diff --git a/test/integration/targets/lookup_ini/test_case_sensitive.yml b/test/integration/targets/lookup_ini/test_case_sensitive.yml
new file mode 100644
index 0000000..f66674c
--- /dev/null
+++ b/test/integration/targets/lookup_ini/test_case_sensitive.yml
@@ -0,0 +1,31 @@
+- name: Test case sensitive option
+ hosts: all
+
+ tasks:
+ - name: Lookup a file with keys that differ only in case with case sensitivity enabled
+ debug:
+ msg: "{{ lookup('ini', 'name', file='duplicate_case_check.ini', section='reggae', case_sensitive=True) }}"
+ register: duplicate_case_sensitive_name
+
+ - name: Lookup a file with keys that differ only in case with case sensitivity enabled
+ debug:
+ msg: "{{ lookup('ini', 'NAME', file='duplicate_case_check.ini', section='reggae', case_sensitive=True) }}"
+ register: duplicate_case_sensitive_NAME
+
+ - name: Lookup a properties file with keys that differ only in case with case sensitivity enabled
+ debug:
+ msg: "{{ lookup('ini', 'name', file='lookup_case_check.properties', type='properties', case_sensitive=True) }}"
+ register: duplicate_case_sensitive_properties_name
+
+ - name: Lookup a properties file with keys that differ only in case with case sensitivity enabled
+ debug:
+ msg: "{{ lookup('ini', 'NAME', file='lookup_case_check.properties', type='properties', case_sensitive=True) }}"
+ register: duplicate_case_sensitive_properties_NAME
+
+ - name: Ensure the correct case-sensitive values were retieved
+ assert:
+ that:
+ - duplicate_case_sensitive_name.msg == 'bob'
+ - duplicate_case_sensitive_NAME.msg == 'marley'
+ - duplicate_case_sensitive_properties_name.msg == 'captain'
+ - duplicate_case_sensitive_properties_NAME.msg == 'fantastic'
diff --git a/test/integration/targets/lookup_ini/test_errors.yml b/test/integration/targets/lookup_ini/test_errors.yml
new file mode 100644
index 0000000..c1832a3
--- /dev/null
+++ b/test/integration/targets/lookup_ini/test_errors.yml
@@ -0,0 +1,62 @@
+- name: Test INI lookup errors
+ hosts: testhost
+
+ tasks:
+ - name: Test for failure on Python 3
+ when: ansible_facts.python.version_info[0] >= 3
+ block:
+ - name: Lookup a file with duplicate keys
+ debug:
+ msg: "{{ lookup('ini', 'name', file='duplicate.ini', section='reggae') }}"
+ ignore_errors: yes
+ register: duplicate
+
+ - name: Lookup a file with keys that differ only in case
+ debug:
+ msg: "{{ lookup('ini', 'name', file='duplicate_case_check.ini', section='reggae') }}"
+ ignore_errors: yes
+ register: duplicate_case_sensitive
+
+ - name: Ensure duplicate key errors were handled properly
+ assert:
+ that:
+ - duplicate is failed
+ - "'Duplicate option in' in duplicate.msg"
+ - duplicate_case_sensitive is failed
+ - "'Duplicate option in' in duplicate_case_sensitive.msg"
+
+ - name: Lookup a file with a missing section
+ debug:
+ msg: "{{ lookup('ini', 'name', file='lookup.ini', section='missing') }}"
+ ignore_errors: yes
+ register: missing_section
+
+ - name: Ensure error was shown for a missing section
+ assert:
+ that:
+ - missing_section is failed
+ - "'No section' in missing_section.msg"
+
+ - name: Mix options type and push key out of order
+ debug:
+ msg: "{{ lookup('ini', 'file=lookup.ini', 'value1', section='value_section') }}"
+ register: bad_mojo
+ ignore_errors: yes
+
+ - name: Verify bad behavior reported an error
+ assert:
+ that:
+ - bad_mojo is failed
+ - '"No key to lookup was provided as first term with in string inline option" in bad_mojo.msg'
+
+ - name: Test invalid option
+ debug:
+ msg: "{{ lookup('ini', 'invalid=option') }}"
+ ignore_errors: yes
+ register: invalid_option
+
+ - name: Ensure invalid option failed
+ assert:
+ that:
+ - invalid_option is failed
+ - "'is not a valid option' in invalid_option.msg"
diff --git a/test/integration/targets/lookup_ini/test_ini.yml b/test/integration/targets/lookup_ini/test_ini.yml
new file mode 100644
index 0000000..11a5e57
--- /dev/null
+++ b/test/integration/targets/lookup_ini/test_ini.yml
@@ -0,0 +1,4 @@
+- import_playbook: test_lookup_properties.yml
+- import_playbook: test_errors.yml
+- import_playbook: test_case_sensitive.yml
+- import_playbook: test_allow_no_value.yml
diff --git a/test/integration/targets/lookup_ini/test_lookup_properties.yml b/test/integration/targets/lookup_ini/test_lookup_properties.yml
new file mode 100644
index 0000000..a6fc0f7
--- /dev/null
+++ b/test/integration/targets/lookup_ini/test_lookup_properties.yml
@@ -0,0 +1,88 @@
+- name: Lookup test
+ hosts: testhost
+
+ tasks:
+ - name: "read properties value"
+ set_fact:
+ test1: "{{lookup('ini', 'value1 type=properties file=lookup.properties')}}"
+ test2: "{{lookup('ini', 'value2', type='properties', file='lookup.properties')}}"
+ test_dot: "{{lookup('ini', 'value.dot', type='properties', file='lookup.properties')}}"
+ field_with_space: "{{lookup('ini', 'field.with.space type=properties file=lookup.properties')}}"
+
+ - assert:
+ that: "{{item}} is defined"
+ with_items: [ 'test1', 'test2', 'test_dot', 'field_with_space' ]
+
+ - name: "read ini value"
+ set_fact:
+ value1_global: "{{lookup('ini', 'value1', section='global', file='lookup.ini')}}"
+ value2_global: "{{lookup('ini', 'value2', section='global', file='lookup.ini')}}"
+ value1_section1: "{{lookup('ini', 'value1', section='section1', file='lookup.ini')}}"
+ field_with_unicode: "{{lookup('ini', 'unicode', section='global', file='lookup.ini')}}"
+
+ - debug: var={{item}}
+ with_items: [ 'value1_global', 'value2_global', 'value1_section1', 'field_with_unicode' ]
+
+ - assert:
+ that:
+ - "field_with_unicode == 'été indien où à château français ïîôû'"
+
+ - name: "read ini value from iso8859-15 file"
+ set_fact:
+ field_with_unicode: "{{lookup('ini', 'field_with_unicode section=global encoding=iso8859-1 file=lookup-8859-15.ini')}}"
+
+ - assert:
+ that:
+ - "field_with_unicode == 'été indien où à château français ïîôû'"
+
+ - name: "read ini value with section and regexp"
+ set_fact:
+ value_section: "{{lookup('ini', 'value[1-2] section=value_section file=lookup.ini re=true')}}"
+ other_section: "{{lookup('ini', 'other[1-2] section=other_section file=lookup.ini re=true')}}"
+
+ - debug: var={{item}}
+ with_items: [ 'value_section', 'other_section' ]
+
+ - assert:
+ that:
+ - "value_section == '1,2'"
+ - "other_section == '4,5'"
+
+ - name: "Reading unknown value"
+ set_fact:
+ unknown: "{{lookup('ini', 'unknown default=unknown section=section1 file=lookup.ini')}}"
+
+ - debug: var=unknown
+
+ - assert:
+ that:
+ - 'unknown == "unknown"'
+
+ - name: "Looping over section section1"
+ debug: msg="{{item}}"
+ with_ini: value[1-2] section=section1 file=lookup.ini re=true
+ register: _
+
+ - assert:
+ that:
+ - '_.results.0.item == "section1/value1"'
+ - '_.results.1.item == "section1/value2"'
+
+ - name: "Looping over section value_section"
+ debug: msg="{{item}}"
+ with_ini: value[1-2] section=value_section file=lookup.ini re=true
+ register: _
+
+ - assert:
+ that:
+ - '_.results.0.item == "1"'
+ - '_.results.1.item == "2"'
+
+ - debug: msg="{{item}}"
+ with_ini: value[1-2] section=section1 file=lookup.ini re=true
+ register: _
+
+ - assert:
+ that:
+ - '_.results.0.item == "section1/value1"'
+ - '_.results.1.item == "section1/value2"'