Skip to content

Instantly share code, notes, and snippets.

@benformosa
Created June 19, 2023 09:51
Show Gist options
  • Save benformosa/7bf92e8975dc912326a0a8f789a47c24 to your computer and use it in GitHub Desktop.
Save benformosa/7bf92e8975dc912326a0a8f789a47c24 to your computer and use it in GitHub Desktop.
---
- name: Reproduce Docker Swarm Service issue
ignore_errors: true
run_once: true
hosts: all
tasks:
- name: Delete service
become: true
community.docker.docker_swarm_service:
name: my_nginx
state: absent
- name: Create config
become: true
community.docker.docker_config:
name: my_nginx_index
data: |
My awesome custom index page
- name: Create service
become: true
community.docker.docker_swarm_service:
name: my_nginx
image: library/nginx:latest
publish:
- target_port: 80
published_port: 80
replicas: 1
configs:
- config_name: my_nginx_index
filename: /usr/share/nginx/html/index.html
- name: wait for service to start
ansible.builtin.wait_for:
timeout: 5
- name: Test 1 uri - create service
register: my_uri
failed_when: "'awesome' not in my_uri.content"
ansible.builtin.uri:
url: http://localhost/index.html
return_content: true
- name: Get swarm info
become: true
register: swarm_info
community.docker.docker_swarm_info:
services: true
verbose_output: true
- name: Test 1 swarm_info - Display service info
ansible.builtin.debug:
msg: "{{ (swarm_info.services | first).Spec.TaskTemplate.ContainerSpec }}"
- name: Scale service down with command
become: true
ansible.builtin.command: docker service update my_nginx --replicas=0
- name: Scale service up with command
become: true
ansible.builtin.command: docker service update my_nginx --replicas=1
- name: Test 2 uri - scale with command
register: my_uri
failed_when: "'awesome' not in my_uri.content"
ansible.builtin.uri:
url: http://localhost/index.html
return_content: true
- name: Get swarm info
become: true
register: swarm_info
community.docker.docker_swarm_info:
services: true
verbose_output: true
- name: Test 2 swarm_info - Display service info
ansible.builtin.debug:
msg: "{{ (swarm_info.services | first).Spec.TaskTemplate.ContainerSpec }}"
- name: Scale service down with module
become: true
community.docker.docker_swarm_service:
name: my_nginx
image: library/nginx:latest
replicas: 0
- name: Scale service up
become: true
community.docker.docker_swarm_service:
name: my_nginx
image: library/nginx:latest
replicas: 1
- name: wait for service to start
ansible.builtin.wait_for:
timeout: 5
- name: Test 3 uri - scale with module
register: my_uri
failed_when: "'awesome' not in my_uri.content"
ansible.builtin.uri:
url: http://localhost/index.html
return_content: true
- name: Get swarm info
become: true
register: swarm_info
community.docker.docker_swarm_info:
services: true
verbose_output: true
- name: Task 3 swarm_info - Display service info
ansible.builtin.debug:
msg: "{{ (swarm_info.services | first).Spec.TaskTemplate.ContainerSpec }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment