summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/ansible-inventory
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/ansible-inventory')
-rw-r--r--test/integration/targets/ansible-inventory/aliases2
-rw-r--r--test/integration/targets/ansible-inventory/files/invalid_sample.yml7
-rw-r--r--test/integration/targets/ansible-inventory/files/unicode.yml3
-rw-r--r--test/integration/targets/ansible-inventory/files/valid_sample.toml2
-rw-r--r--test/integration/targets/ansible-inventory/files/valid_sample.yml7
-rwxr-xr-xtest/integration/targets/ansible-inventory/runme.sh7
-rw-r--r--test/integration/targets/ansible-inventory/tasks/main.yml147
-rw-r--r--test/integration/targets/ansible-inventory/tasks/toml.yml66
-rw-r--r--test/integration/targets/ansible-inventory/test.yml3
9 files changed, 244 insertions, 0 deletions
diff --git a/test/integration/targets/ansible-inventory/aliases b/test/integration/targets/ansible-inventory/aliases
new file mode 100644
index 0000000..498fedd
--- /dev/null
+++ b/test/integration/targets/ansible-inventory/aliases
@@ -0,0 +1,2 @@
+shippable/posix/group4
+context/controller
diff --git a/test/integration/targets/ansible-inventory/files/invalid_sample.yml b/test/integration/targets/ansible-inventory/files/invalid_sample.yml
new file mode 100644
index 0000000..f7bbe0c
--- /dev/null
+++ b/test/integration/targets/ansible-inventory/files/invalid_sample.yml
@@ -0,0 +1,7 @@
+all:
+ children:
+ somegroup:
+ hosts:
+ something:
+ 7.2: bar
+ ungrouped: {}
diff --git a/test/integration/targets/ansible-inventory/files/unicode.yml b/test/integration/targets/ansible-inventory/files/unicode.yml
new file mode 100644
index 0000000..ff95db0
--- /dev/null
+++ b/test/integration/targets/ansible-inventory/files/unicode.yml
@@ -0,0 +1,3 @@
+all:
+ hosts:
+ příbor:
diff --git a/test/integration/targets/ansible-inventory/files/valid_sample.toml b/test/integration/targets/ansible-inventory/files/valid_sample.toml
new file mode 100644
index 0000000..6d83b6f
--- /dev/null
+++ b/test/integration/targets/ansible-inventory/files/valid_sample.toml
@@ -0,0 +1,2 @@
+[somegroup.hosts.something]
+foo = "bar"
diff --git a/test/integration/targets/ansible-inventory/files/valid_sample.yml b/test/integration/targets/ansible-inventory/files/valid_sample.yml
new file mode 100644
index 0000000..477f82f
--- /dev/null
+++ b/test/integration/targets/ansible-inventory/files/valid_sample.yml
@@ -0,0 +1,7 @@
+all:
+ children:
+ somegroup:
+ hosts:
+ something:
+ foo: bar
+ ungrouped: {} \ No newline at end of file
diff --git a/test/integration/targets/ansible-inventory/runme.sh b/test/integration/targets/ansible-inventory/runme.sh
new file mode 100755
index 0000000..6f3e342
--- /dev/null
+++ b/test/integration/targets/ansible-inventory/runme.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+source virtualenv.sh
+export ANSIBLE_ROLES_PATH=../
+set -euvx
+
+ansible-playbook test.yml "$@"
diff --git a/test/integration/targets/ansible-inventory/tasks/main.yml b/test/integration/targets/ansible-inventory/tasks/main.yml
new file mode 100644
index 0000000..84ac2c3
--- /dev/null
+++ b/test/integration/targets/ansible-inventory/tasks/main.yml
@@ -0,0 +1,147 @@
+- name: "No command supplied"
+ command: ansible-inventory
+ ignore_errors: true
+ register: result
+
+- assert:
+ that:
+ - result is failed
+ - '"ERROR! No action selected, at least one of --host, --graph or --list needs to be specified." in result.stderr'
+
+- name: "test option: --list --export"
+ command: ansible-inventory --list --export
+ register: result
+
+- assert:
+ that:
+ - result is succeeded
+
+- name: "test option: --list --yaml --export"
+ command: ansible-inventory --list --yaml --export
+ register: result
+
+- assert:
+ that:
+ - result is succeeded
+
+- name: "test option: --list --output"
+ command: ansible-inventory --list --output junk.txt
+ register: result
+
+- name: stat output file
+ stat:
+ path: junk.txt
+ register: st
+
+- assert:
+ that:
+ - result is succeeded
+ - st.stat.exists
+
+- name: "test option: --graph"
+ command: ansible-inventory --graph
+ register: result
+
+- assert:
+ that:
+ - result is succeeded
+
+- name: "test option: --graph --vars"
+ command: ansible-inventory --graph --vars
+ register: result
+
+- assert:
+ that:
+ - result is succeeded
+
+- name: "test option: --graph with bad pattern"
+ command: ansible-inventory --graph invalid
+ ignore_errors: true
+ register: result
+
+- assert:
+ that:
+ - result is failed
+ - '"ERROR! Pattern must be valid group name when using --graph" in result.stderr'
+
+- name: "test option: --host localhost"
+ command: ansible-inventory --host localhost
+ register: result
+
+- assert:
+ that:
+ - result is succeeded
+
+- name: "test option: --host with invalid host"
+ command: ansible-inventory --host invalid
+ ignore_errors: true
+ register: result
+
+- assert:
+ that:
+ - result is failed
+ - '"ERROR! Could not match supplied host pattern, ignoring: invalid" in result.stderr'
+
+- name: "test json output with unicode characters"
+ command: ansible-inventory --list -i {{ role_path }}/files/unicode.yml
+ register: result
+
+- assert:
+ that:
+ - result is succeeded
+ - result.stdout is contains('příbor')
+
+- block:
+ - name: "test json output file with unicode characters"
+ command: ansible-inventory --list --output unicode_inventory.json -i {{ role_path }}/files/unicode.yml
+
+ - set_fact:
+ json_inventory_file: "{{ lookup('file', 'unicode_inventory.json') }}"
+
+ - assert:
+ that:
+ - json_inventory_file|string is contains('příbor')
+ always:
+ - file:
+ name: unicode_inventory.json
+ state: absent
+
+- name: "test yaml output with unicode characters"
+ command: ansible-inventory --list --yaml -i {{ role_path }}/files/unicode.yml
+ register: result
+
+- assert:
+ that:
+ - result is succeeded
+ - result.stdout is contains('příbor')
+
+- block:
+ - name: "test yaml output file with unicode characters"
+ command: ansible-inventory --list --yaml --output unicode_inventory.yaml -i {{ role_path }}/files/unicode.yml
+
+ - set_fact:
+ yaml_inventory_file: "{{ lookup('file', 'unicode_inventory.yaml') | string }}"
+
+ - assert:
+ that:
+ - yaml_inventory_file is contains('příbor')
+ always:
+ - file:
+ name: unicode_inventory.yaml
+ state: absent
+
+- include_tasks: toml.yml
+ loop:
+ -
+ - toml<0.10.0
+ -
+ - toml
+ -
+ - tomli
+ - tomli-w
+ -
+ - tomllib
+ - tomli-w
+ loop_control:
+ loop_var: toml_package
+ when: toml_package is not contains 'tomllib' or (toml_package is contains 'tomllib' and ansible_facts.python.version_info >= [3, 11])
diff --git a/test/integration/targets/ansible-inventory/tasks/toml.yml b/test/integration/targets/ansible-inventory/tasks/toml.yml
new file mode 100644
index 0000000..4a227dd
--- /dev/null
+++ b/test/integration/targets/ansible-inventory/tasks/toml.yml
@@ -0,0 +1,66 @@
+- name: Ensure no toml packages are installed
+ pip:
+ name:
+ - tomli
+ - tomli-w
+ - toml
+ state: absent
+
+- name: Install toml package
+ pip:
+ name: '{{ toml_package|difference(["tomllib"]) }}'
+ state: present
+
+- name: test toml parsing
+ command: ansible-inventory --list --toml -i {{ role_path }}/files/valid_sample.toml
+ register: toml_in
+
+- assert:
+ that:
+ - >
+ 'foo = "bar"' in toml_in.stdout
+
+- name: "test option: --toml with valid group name"
+ command: ansible-inventory --list --toml -i {{ role_path }}/files/valid_sample.yml
+ register: result
+
+- assert:
+ that:
+ - result is succeeded
+
+- name: "test option: --toml with invalid group name"
+ command: ansible-inventory --list --toml -i {{ role_path }}/files/invalid_sample.yml
+ ignore_errors: true
+ register: result
+
+- assert:
+ that:
+ - result is failed
+ - >
+ "ERROR! The source inventory contains" in result.stderr
+
+- block:
+ - name: "test toml output with unicode characters"
+ command: ansible-inventory --list --toml -i {{ role_path }}/files/unicode.yml
+ register: result
+
+ - assert:
+ that:
+ - result is succeeded
+ - result.stdout is contains('příbor')
+
+ - block:
+ - name: "test toml output file with unicode characters"
+ command: ansible-inventory --list --toml --output unicode_inventory.toml -i {{ role_path }}/files/unicode.yml
+
+ - set_fact:
+ toml_inventory_file: "{{ lookup('file', 'unicode_inventory.toml') | string }}"
+
+ - assert:
+ that:
+ - toml_inventory_file is contains('příbor')
+ always:
+ - file:
+ name: unicode_inventory.toml
+ state: absent
+ when: ansible_python.version.major|int == 3
diff --git a/test/integration/targets/ansible-inventory/test.yml b/test/integration/targets/ansible-inventory/test.yml
new file mode 100644
index 0000000..38b3686
--- /dev/null
+++ b/test/integration/targets/ansible-inventory/test.yml
@@ -0,0 +1,3 @@
+- hosts: localhost
+ roles:
+ - ansible-inventory