summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Tanner <tanner.jc@gmail.com>2014-02-21 11:34:06 -0500
committerJames Tanner <tanner.jc@gmail.com>2014-02-21 11:34:06 -0500
commit65e58c21ddca017963f854ab9035eb5fe169c58e (patch)
treea05378dd947c73c8fa1e6a72a8380888055f562d
parent799fe2c289dfa3349940128553256f33142d7902 (diff)
downloadansible-65e58c21ddca017963f854ab9035eb5fe169c58e.tar.gz
Add test for basic lookups
-rw-r--r--test/integration/non_destructive.yml1
-rw-r--r--test/integration/roles/test_lookups/meta/main.yml3
-rw-r--r--test/integration/roles/test_lookups/tasks/main.yml84
3 files changed, 88 insertions, 0 deletions
diff --git a/test/integration/non_destructive.yml b/test/integration/non_destructive.yml
index fe477e2764..91e86157d9 100644
--- a/test/integration/non_destructive.yml
+++ b/test/integration/non_destructive.yml
@@ -30,4 +30,5 @@
- { role: test_conditionals, tags: test_conditionals }
- { role: test_async, tags: test_async }
- { role: test_handlers, tags: test_handlers }
+ - { role: test_lookups, tags: test_lookups }
diff --git a/test/integration/roles/test_lookups/meta/main.yml b/test/integration/roles/test_lookups/meta/main.yml
new file mode 100644
index 0000000000..1050c23ce3
--- /dev/null
+++ b/test/integration/roles/test_lookups/meta/main.yml
@@ -0,0 +1,3 @@
+dependencies:
+ - prepare_tests
+
diff --git a/test/integration/roles/test_lookups/tasks/main.yml b/test/integration/roles/test_lookups/tasks/main.yml
new file mode 100644
index 0000000000..d54b769ecb
--- /dev/null
+++ b/test/integration/roles/test_lookups/tasks/main.yml
@@ -0,0 +1,84 @@
+# test code for lookup plugins
+# (c) 2014, James Tanner <tanner.jc@gmail.com>
+
+# This file is part of Ansible
+#
+# Ansible is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Ansible is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
+
+# FILE LOOKUP
+
+- name: make a new file to read
+ copy: dest={{output_dir}}/foo.txt mode=0644 content="bar"
+
+- name: load the file as a fact
+ set_fact:
+ foo: "{{ lookup('file', output_dir + '/foo.txt' ) }}"
+
+- debug: var=foo
+
+- name: verify file lookup
+ assert:
+ that:
+ - "foo == 'bar'"
+
+
+# PASSWORD LOOKUP
+
+- name: remove previous password files
+ file: dest={{output_dir}}/password state=absent
+
+- name: create a password file
+ set_fact:
+ newpass: "{{ lookup('password', output_dir + '/password length=8') }}"
+
+- name: get password length
+ shell: wc -c {{output_dir}}/password | awk '{print $1}'
+ register: wc_result
+
+- debug: var=wc_result.stdout
+
+- name: read password
+ shell: cat {{output_dir}}/password
+ register: cat_result
+
+- debug: var=cat_result.stdout
+
+- name: verify password
+ assert:
+ that:
+ - "wc_result.stdout == '9'"
+ - "cat_result.stdout == newpass"
+
+# ENV LOOKUP
+
+- name: get first environment var name
+ shell: env | head -n1 | cut -d\= -f1
+ register: known_var_name
+
+- name: get first environment var value
+ shell: echo {{ '$' + known_var_name.stdout }}
+ register: known_var_value
+
+- name: use env lookup to get known var
+ set_fact:
+ test_val: "{{ lookup('env', known_var_name.stdout) }}"
+
+- debug: var=known_var_name.stdout
+- debug: var=known_var_value.stdout
+- debug: var=test_val
+
+- name: compare values
+ assert:
+ that:
+ - "test_val == known_var_value.stdout"