Last active
December 11, 2022 17:14
-
-
Save pwalkr/aefc527c1e4ff01e5e6861eb8700efca to your computer and use it in GitHub Desktop.
Find (gitlab) container/node in swarm for executing backup via ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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