From 7fb1519035a711761a6f50cb92bcb37c6b69e901 Mon Sep 17 00:00:00 2001 From: Brendan Jurd Date: Mon, 27 Jul 2015 21:38:34 +1000 Subject: [PATCH] Add integration tests for group_by precedence. Test that, when a group is created with group_by, variables from the corresponding group_vars/ file are correctly pulled in, and override variables specified in group_vars/all. See ansible/ansible#8664. --- .../targets/group_by/group_vars/camelus | 1 + .../targets/group_by/group_vars/vicugna | 1 + .../targets/group_by/inventory.group_by | 3 + .../targets/group_by/test_group_by.yml | 62 ++++++++++++++++++- 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 test/integration/targets/group_by/group_vars/camelus create mode 100644 test/integration/targets/group_by/group_vars/vicugna diff --git a/test/integration/targets/group_by/group_vars/camelus b/test/integration/targets/group_by/group_vars/camelus new file mode 100644 index 0000000000..b214ad6962 --- /dev/null +++ b/test/integration/targets/group_by/group_vars/camelus @@ -0,0 +1 @@ +dos: 'two' diff --git a/test/integration/targets/group_by/group_vars/vicugna b/test/integration/targets/group_by/group_vars/vicugna new file mode 100644 index 0000000000..8feb93fc99 --- /dev/null +++ b/test/integration/targets/group_by/group_vars/vicugna @@ -0,0 +1 @@ +tres: 'three' diff --git a/test/integration/targets/group_by/inventory.group_by b/test/integration/targets/group_by/inventory.group_by index d8d285dee5..9c7fe7ee71 100644 --- a/test/integration/targets/group_by/inventory.group_by +++ b/test/integration/targets/group_by/inventory.group_by @@ -1,3 +1,6 @@ +# ungrouped +camel genus=camelus ansible_connection=local + [lamini] alpaca genus=vicugna llama genus=lama diff --git a/test/integration/targets/group_by/test_group_by.yml b/test/integration/targets/group_by/test_group_by.yml index 3c299aa728..21f76bcb22 100644 --- a/test/integration/targets/group_by/test_group_by.yml +++ b/test/integration/targets/group_by/test_group_by.yml @@ -17,7 +17,7 @@ # along with Ansible. If not, see . - name: Create overall groups - hosts: lamini + hosts: all gather_facts: false tasks: - debug: var=genus @@ -51,6 +51,15 @@ - name: set a fact to check that we ran this play set_fact: genus_lama=true +- name: Camelus group validation + hosts: camelus + gather_facts: false + tasks: + - name: verify that only the camel is in this group + assert: { that: "inventory_hostname == 'camel'" } + - name: set a fact to check that we ran this play + set_fact: genus_camelus=true + - name: Vic group validation hosts: vic gather_facts: false @@ -69,6 +78,15 @@ - name: set a fact to check that we ran this play set_fact: genus_lam=true +- name: Cam group validation + hosts: cam + gather_facts: false + tasks: + - name: verify that only the camel is in this group + assert: { that: "inventory_hostname == 'camel'" } + - name: set a fact to check that we ran this play + set_fact: genus_cam=true + - name: Vi group validation hosts: vi gather_facts: false @@ -87,6 +105,15 @@ - name: set a fact to check that we ran this play set_fact: genus_la=true +- name: Ca group validation + hosts: ca + gather_facts: false + tasks: + - name: verify that only the camel is in this group + assert: { that: "inventory_hostname == 'camel'" } + - name: set a fact to check that we ran this play + set_fact: genus_ca=true + - name: VICUGNA group validation hosts: VICUGNA gather_facts: false @@ -105,6 +132,15 @@ - name: set a fact to check that we ran this play set_fact: genus_LAMA=true +- name: CAMELUS group validation + hosts: CAMELUS + gather_facts: false + tasks: + - name: verify that only the camel is in this group + assert: { that: "inventory_hostname == 'camel'" } + - name: set a fact to check that we ran this play + set_fact: genus_CAMELUS=true + - name: genus group validation (expect skipped) hosts: 'genus' gather_facts: false @@ -125,3 +161,27 @@ tasks: - name: check that llama matched all four groups assert: { that: ["genus_lama", "genus_lam", "genus_la", "genus_LAMA"] } + +- hosts: camel + gather_facts: false + tasks: + - name: check that camel matched all four groups + assert: { that: ["genus_camelus", "genus_cam", "genus_ca", "genus_CAMELUS"] } + +- hosts: vicugna + gather_facts: false + tasks: + - name: check group_vars variable overrides for vicugna + assert: { that: ["uno == 1", "dos == 2", "tres == 'three'"] } + +- hosts: lama + gather_facts: false + tasks: + - name: check group_vars variable overrides for lama + assert: { that: ["uno == 1", "dos == 2", "tres == 3"] } + +- hosts: camelus + gather_facts: false + tasks: + - name: check group_vars variable overrides for camelus + assert: { that: ["uno == 1", "dos == 'two'", "tres == 3"] }