Skip to content

Instantly share code, notes, and snippets.

@pwalkr
Last active December 11, 2022 17:14
Show Gist options
  • Save pwalkr/aefc527c1e4ff01e5e6861eb8700efca to your computer and use it in GitHub Desktop.
Save pwalkr/aefc527c1e4ff01e5e6861eb8700efca to your computer and use it in GitHub Desktop.
Find (gitlab) container/node in swarm for executing backup via ansible
# Run on a swarm manager node
- name: find container and node
shell: |
set -e
{% raw %}
task_id="$(docker stack ps gitlab --filter desired-state=running --format="{{.ID}}")"
# stdout_lines[0]
docker inspect $task_id --format="{{.Status.ContainerStatus.ContainerID}}"
node_id="$(docker inspect $task_id --format="{{.NodeID}}")"
# stdout_lines[1]
docker node ls --filter id=$node_id --format="{{.Hostname}}"
{% endraw %}
register: found
- name: run gitlab-backup
command: 'docker exec {{ found.stdout_lines[0] }} which gitlab-backup'
delegate_to: '{{ found.stdout_lines[1] }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment