From 791176252b17c190913ef068051dbe2e1f617ba4 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 26 Mar 2019 14:44:42 +0100 Subject: [PATCH] docker_swarm inventory: fix tests, and make sure that they fail if no host is found (#54380) * Fix tests, and make sure that they fail if no host is found. * Fix interpreter. --- .../inventory_1.docker_swarm.yml | 2 +- .../inventory_2.docker_swarm.yml | 2 +- .../playbooks/test_inventory_1.yml | 20 +++++++++++++++++++ .../playbooks/test_inventory_2.yml | 20 +++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/test/integration/targets/inventory_docker_swarm/inventory_1.docker_swarm.yml b/test/integration/targets/inventory_docker_swarm/inventory_1.docker_swarm.yml index 4ccbab6f62e..e8e6d55e5e3 100644 --- a/test/integration/targets/inventory_docker_swarm/inventory_1.docker_swarm.yml +++ b/test/integration/targets/inventory_docker_swarm/inventory_1.docker_swarm.yml @@ -1,3 +1,3 @@ --- plugin: docker_swarm -host: unix://var/run/docker.sock +docker_host: unix://var/run/docker.sock diff --git a/test/integration/targets/inventory_docker_swarm/inventory_2.docker_swarm.yml b/test/integration/targets/inventory_docker_swarm/inventory_2.docker_swarm.yml index 4c9addd51bf..e36bd00f93a 100644 --- a/test/integration/targets/inventory_docker_swarm/inventory_2.docker_swarm.yml +++ b/test/integration/targets/inventory_docker_swarm/inventory_2.docker_swarm.yml @@ -1,5 +1,5 @@ --- plugin: docker_swarm -host: unix://var/run/docker.sock +docker_host: unix://var/run/docker.sock verbose_output: no include_host_uri: yes diff --git a/test/integration/targets/inventory_docker_swarm/playbooks/test_inventory_1.yml b/test/integration/targets/inventory_docker_swarm/playbooks/test_inventory_1.yml index 1f80bcce941..600a89b1dad 100644 --- a/test/integration/targets/inventory_docker_swarm/playbooks/test_inventory_1.yml +++ b/test/integration/targets/inventory_docker_swarm/playbooks/test_inventory_1.yml @@ -1,6 +1,26 @@ --- +- hosts: 127.0.0.1 + connection: local # otherwise Ansible will complain that it cannot connect via ssh to 127.0.0.1:22 + gather_facts: no + tasks: + - name: Show all groups + debug: + var: groups + - name: Make sure docker_swarm groups are there + assert: + that: + - groups.all | length > 0 + - groups.leader | length == 1 + - groups.manager | length > 0 + - groups.worker | length >= 0 + - groups.nonleaders | length >= 0 + - hosts: all connection: local # otherwise Ansible will complain that it cannot connect via ssh to 127.0.0.1:22 + vars: + # for some reason, Ansible can't find the Python interpreter when connecting to the nodes, + # which is in fact just localhost in disguise. That's why we use ansible_playbook_python. + ansible_python_interpreter: "{{ ansible_playbook_python }}" tasks: - name: Check for groups assert: diff --git a/test/integration/targets/inventory_docker_swarm/playbooks/test_inventory_2.yml b/test/integration/targets/inventory_docker_swarm/playbooks/test_inventory_2.yml index 97283c2c48a..b2a794d35bf 100644 --- a/test/integration/targets/inventory_docker_swarm/playbooks/test_inventory_2.yml +++ b/test/integration/targets/inventory_docker_swarm/playbooks/test_inventory_2.yml @@ -1,6 +1,26 @@ --- +- hosts: 127.0.0.1 + connection: local # otherwise Ansible will complain that it cannot connect via ssh to 127.0.0.1:22 + gather_facts: no + tasks: + - name: Show all groups + debug: + var: groups + - name: Make sure docker_swarm groups are there + assert: + that: + - groups.all | length > 0 + - groups.leader | length == 1 + - groups.manager | length > 0 + - groups.worker | length >= 0 + - groups.nonleaders | length >= 0 + - hosts: all connection: local # otherwise Ansible will complain that it cannot connect via ssh to 127.0.0.1:22 + vars: + # for some reason, Ansible can't find the Python interpreter when connecting to the nodes, + # which is in fact just localhost in disguise. That's why we use ansible_playbook_python. + ansible_python_interpreter: "{{ ansible_playbook_python }}" tasks: - name: Make sure docker_swarm_node_attributes is not available assert: