From 29aea9ff3466e4cd2ed00524b9e56738d568ce8b Mon Sep 17 00:00:00 2001 From: abikouo <79859644+abikouo@users.noreply.github.com> Date: Tue, 13 Apr 2021 17:59:50 +0200 Subject: constructed - Add keyed_groups suboptions 'default_value' and 'trailing_separator' (#74005) * Support omitting the trailing separator when a dictionary key's value is an empty string * Support a default value when the value used in the group name is an empty string * Add tests * change log --- .../keyed_group_default_value.yml | 5 ++++ .../keyed_group_list_default_value.yml | 5 ++++ .../keyed_group_str_default_value.yml | 5 ++++ .../keyed_group_trailing_separator.yml | 5 ++++ .../targets/inventory_constructed/runme.sh | 29 +++++++++++++++++++++- .../inventory_constructed/tag_inventory.yml | 12 +++++++++ 6 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/integration/targets/inventory_constructed/keyed_group_default_value.yml create mode 100644 test/integration/targets/inventory_constructed/keyed_group_list_default_value.yml create mode 100644 test/integration/targets/inventory_constructed/keyed_group_str_default_value.yml create mode 100644 test/integration/targets/inventory_constructed/keyed_group_trailing_separator.yml create mode 100644 test/integration/targets/inventory_constructed/tag_inventory.yml (limited to 'test/integration/targets/inventory_constructed') diff --git a/test/integration/targets/inventory_constructed/keyed_group_default_value.yml b/test/integration/targets/inventory_constructed/keyed_group_default_value.yml new file mode 100644 index 0000000000..e4d0a76b7e --- /dev/null +++ b/test/integration/targets/inventory_constructed/keyed_group_default_value.yml @@ -0,0 +1,5 @@ +plugin: constructed +keyed_groups: + - key: tags + prefix: tag + default_value: "running" diff --git a/test/integration/targets/inventory_constructed/keyed_group_list_default_value.yml b/test/integration/targets/inventory_constructed/keyed_group_list_default_value.yml new file mode 100644 index 0000000000..1c2d00e06e --- /dev/null +++ b/test/integration/targets/inventory_constructed/keyed_group_list_default_value.yml @@ -0,0 +1,5 @@ +plugin: constructed +keyed_groups: + - key: roles + default_value: storage + prefix: host \ No newline at end of file diff --git a/test/integration/targets/inventory_constructed/keyed_group_str_default_value.yml b/test/integration/targets/inventory_constructed/keyed_group_str_default_value.yml new file mode 100644 index 0000000000..ae3fd5ae39 --- /dev/null +++ b/test/integration/targets/inventory_constructed/keyed_group_str_default_value.yml @@ -0,0 +1,5 @@ +plugin: constructed +keyed_groups: + - key: os + default_value: "fedora" + prefix: host \ No newline at end of file diff --git a/test/integration/targets/inventory_constructed/keyed_group_trailing_separator.yml b/test/integration/targets/inventory_constructed/keyed_group_trailing_separator.yml new file mode 100644 index 0000000000..cbe57c6098 --- /dev/null +++ b/test/integration/targets/inventory_constructed/keyed_group_trailing_separator.yml @@ -0,0 +1,5 @@ +plugin: constructed +keyed_groups: + - key: tags + prefix: tag + trailing_separator: False diff --git a/test/integration/targets/inventory_constructed/runme.sh b/test/integration/targets/inventory_constructed/runme.sh index 0cd1a29311..91bbd66bde 100755 --- a/test/integration/targets/inventory_constructed/runme.sh +++ b/test/integration/targets/inventory_constructed/runme.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -ex +set -eux ansible-inventory -i static_inventory.yml -i constructed.yml --graph | tee out.txt @@ -24,6 +24,33 @@ grep '@prefix_hostvalue1' out.txt grep '@prefix_item0' out.txt grep '@prefix_key0_value0' out.txt +# keyed group with default value for key's value empty (dict) +ansible-inventory -i tag_inventory.yml -i keyed_group_default_value.yml --graph | tee out.txt + +grep '@tag_name_host0' out.txt +grep '@tag_environment_test' out.txt +grep '@tag_status_running' out.txt + +# keyed group with default value for key's value empty (list) +ansible-inventory -i tag_inventory.yml -i keyed_group_list_default_value.yml --graph | tee out.txt + +grep '@host_db' out.txt +grep '@host_web' out.txt +grep '@host_storage' out.txt + +# keyed group with default value for key's value empty (str) +ansible-inventory -i tag_inventory.yml -i keyed_group_str_default_value.yml --graph | tee out.txt + +grep '@host_fedora' out.txt + + +# keyed group with 'trailing_separator' set to 'False' for key's value empty +ansible-inventory -i tag_inventory.yml -i keyed_group_trailing_separator.yml --graph | tee out.txt + +grep '@tag_name_host0' out.txt +grep '@tag_environment_test' out.txt +grep '@tag_status' out.txt + # test using use_vars_plugins ansible-inventory -i invs/1/one.yml -i invs/2/constructed.yml --graph | tee out.txt diff --git a/test/integration/targets/inventory_constructed/tag_inventory.yml b/test/integration/targets/inventory_constructed/tag_inventory.yml new file mode 100644 index 0000000000..acf810ea21 --- /dev/null +++ b/test/integration/targets/inventory_constructed/tag_inventory.yml @@ -0,0 +1,12 @@ +all: + hosts: + host0: + tags: + name: "host0" + environment: "test" + status: "" + os: "" + roles: + - db + - web + - "" -- cgit v1.2.1