Skip to content

Commit

Permalink
workaround reset_connection action issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
atosatto committed Nov 9, 2019
1 parent c3358bb commit 7396032
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 8 additions & 5 deletions tasks/docker_group.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
4 changes: 2 additions & 2 deletions tasks/docker_py.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---

# 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
state: present
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
Expand Down
5 changes: 3 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions tasks/reset_connection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

- meta: reset_connection
2 changes: 1 addition & 1 deletion tasks/swarm_cluster.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---

- name: Create a custom swarm network
- name: Create a custom swarm network.
docker_network:
name: docker_gwbridge
driver_options:
Expand Down
6 changes: 3 additions & 3 deletions tasks/swarm_labels.yml
Original file line number Diff line number Diff line change
@@ -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 %}
Expand All @@ -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
Expand All @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit 7396032

Please sign in to comment.