diff --git a/meta/main.yml b/meta/main.yml index 15acc72..76c8487 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -3,7 +3,7 @@ galaxy_info: author: Andrea Tosatto description: Setup a Docker Swarm Cluster on Centos/RHEL, Ubuntu/Debian. - min_ansible_version: 2.3 + min_ansible_version: 2.2 license: MIT issue_tracker_url: https://github.com/atosatto/ansible-dockerswarm/issues diff --git a/tasks/docker_group.yml b/tasks/docker_group.yml index 5f4878c..409b2b6 100644 --- a/tasks/docker_group.yml +++ b/tasks/docker_group.yml @@ -12,7 +12,7 @@ - block: # See http://stackoverflow.com/a/37337848/1370301 - - name: Kill the ansible_user active SSH connections + - name: Reset ansible connection after group changes (Ansible < 2.3.0). shell: "sleep 1; pkill -u {{ ansible_user }} {{ ssh_daemon }}" async: 3 # fail after 3 seconds of waiting poll: 2 # wait 2 seconds befor polling the task status @@ -21,12 +21,15 @@ and (ansible_version.full | version_compare('2.3.0.0', '<')) # See https://stackoverflow.com/a/44753457 - - name: Reset ansible connection after group changes - meta: reset_connection + - name: Reset ansible connection after group changes (Ansible >= 2.3.0). + include: reset_connection.yml + static: no # we need to force dynamic inclusion here to avoid 'reset_connection' to be + # always executed even if the when condition evaluates to false on Ansible 2.4.x + # or to generate syntax errors on Ansible < 2.3 when: ansible_version is defined and (ansible_version.full | version_compare('2.3.0.0', '>=')) - when: ansible_user is defined + when: ansible_connection in ['ssh', 'smart'] + and ansible_user is defined and ansible_user in docker_admin_users and ansible_user in (addtogroup.results | selectattr('changed') | map(attribute='item') | list) - and ansible_connection == 'ssh' diff --git a/tasks/docker_py.yml b/tasks/docker_py.yml index 6b544a5..bc0ffbb 100644 --- a/tasks/docker_py.yml +++ b/tasks/docker_py.yml @@ -1,7 +1,7 @@ --- # Specified version because of https://github.com/ansible/ansible/issues/17495 -- name: Install docker-py 1.9.0 +- name: Install docker-py 1.9.0. pip: name: docker-py version: 1.9.0 @@ -9,7 +9,7 @@ when: ansible_version is defined and ansible_version.full | version_compare('2.2.0.0', '<') -- name: Install docker-py +- name: Install docker-py. pip: name: docker-py state: present diff --git a/tasks/main.yml b/tasks/main.yml index 87e0f3b..ef1b797 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,8 +5,9 @@ include_vars: "{{ ansible_os_family }}.yml" # Makes sure that the repo cache is fresh -- name: Update APT cache - apt: update_cache=yes +- name: Update APT cache. + apt: + update_cache: yes when: ansible_os_family == 'Debian' changed_when: false diff --git a/tasks/reset_connection.yml b/tasks/reset_connection.yml new file mode 100644 index 0000000..3005711 --- /dev/null +++ b/tasks/reset_connection.yml @@ -0,0 +1,3 @@ +--- + +- meta: reset_connection diff --git a/tasks/swarm_cluster.yml b/tasks/swarm_cluster.yml index 899adfd..0523a7d 100644 --- a/tasks/swarm_cluster.yml +++ b/tasks/swarm_cluster.yml @@ -1,6 +1,6 @@ --- -- name: Create a custom swarm network +- name: Create a custom swarm network. docker_network: name: docker_gwbridge driver_options: diff --git a/tasks/swarm_labels.yml b/tasks/swarm_labels.yml index 5c62010..93365ef 100644 --- a/tasks/swarm_labels.yml +++ b/tasks/swarm_labels.yml @@ -1,6 +1,6 @@ --- -- name: Get list of labels +- name: Get list of labels. command: >- docker inspect --format {% raw %}'{{range $key, $value := .Spec.Labels}}{{printf "%s\n" $key}}{{end}}'{% endraw %} @@ -13,7 +13,7 @@ - skip_ansible_lint - swarm_labels -- name: Remove labels from swarm node +- name: Remove labels from swarm node. command: docker node update --label-rm {{ item }} {{ ansible_hostname }} with_items: "{{ docker_swarm_labels.stdout_lines }}" when: item not in swarm_labels @@ -23,7 +23,7 @@ - skip_ansible_lint - swarm_labels -- name: Assign labels to swarm nodes | if any +- name: Assign labels to swarm nodes if any. command: docker node update --label-add {{ item }}=true {{ ansible_hostname }} when: item not in docker_swarm_labels.stdout_lines with_items: diff --git a/tox.ini b/tox.ini index 0952e88..b2c4f89 100644 --- a/tox.ini +++ b/tox.ini @@ -7,8 +7,8 @@ skipsdist = true passenv = * deps = -rtest-requirements.txt - ansible22: ansible==2.2 - ansible23: ansible==2.3 - ansible24: ansible==2.4 + ansible22: ansible<2.3 + ansible23: ansible<2.4 + ansible24: ansible<2.5 commands = - {posargs:molecule test --all} + {posargs:molecule test --all --destroy always}