mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
New docker_stack_module with tests (#576)
* First docker stack info approach without tests Fixes results when no stack availabl Fixes sanity test Fixing links Fixes tabs Fixes long line Improving Json Output Changes arguments Lint with autopep8 Moves imports Adds extra line Adds Tests Adds pip and fixes return empty Fixes silly missing else * Adds Tests and Fixes comments * Removes tasks option * Removes arguments * Changes error message * Changes Tests * Add proposals f * Improve output * Change test for output change * Add debug
This commit is contained in:
parent
233617fdfa
commit
bc5dde0e25
9 changed files with 201 additions and 0 deletions
|
@ -0,0 +1,5 @@
|
|||
- include_tasks: test_stack_info.yml
|
||||
when: docker_api_version is version('1.25', '>=')
|
||||
|
||||
- fail: msg="Too old docker / docker-py version to run docker_stack tests!"
|
||||
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
|
|
@ -0,0 +1,75 @@
|
|||
---
|
||||
- block:
|
||||
- name: Make sure we're not already using Docker swarm
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
|
||||
- name: Get docker_stack_info when docker is not running in swarm mode
|
||||
docker_stack_info:
|
||||
ignore_errors: true
|
||||
register: output
|
||||
|
||||
- name: Assert failure when called when swarm is not running
|
||||
assert:
|
||||
that:
|
||||
- 'output is failed'
|
||||
- '"Error running docker stack" in output.msg'
|
||||
|
||||
- name: Create a swarm cluster
|
||||
docker_swarm:
|
||||
state: present
|
||||
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||
|
||||
- name: Get docker_stack_info when docker is running and not stack available
|
||||
docker_stack_info:
|
||||
register: output
|
||||
|
||||
- name: Assert stack facts
|
||||
assert:
|
||||
that:
|
||||
- 'output.results | type_debug == "list"'
|
||||
- 'output.results | length == 0'
|
||||
|
||||
- name: Copy compose files
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: "{{ output_dir }}/"
|
||||
with_items:
|
||||
- stack_compose_base.yml
|
||||
- stack_compose_overrides.yml
|
||||
|
||||
- name: Install docker_stack python requirements
|
||||
pip:
|
||||
name: jsondiff,pyyaml
|
||||
|
||||
- name: Create stack with compose file
|
||||
register: output
|
||||
docker_stack:
|
||||
state: present
|
||||
name: test_stack
|
||||
compose:
|
||||
- "{{ output_dir }}/stack_compose_base.yml"
|
||||
|
||||
- name: Assert test_stack changed on stack creation with compose file
|
||||
assert:
|
||||
that:
|
||||
- output is changed
|
||||
|
||||
- name: Get docker_stack_info when docker is running
|
||||
docker_stack_info:
|
||||
register: output
|
||||
|
||||
- name: assert stack facts
|
||||
assert:
|
||||
that:
|
||||
- 'output.results | type_debug == "list"'
|
||||
- 'output.results[0].Name == "test_stack"'
|
||||
- 'output.results[0].Orchestrator == "Swarm"'
|
||||
- 'output.results[0].Services == "1"'
|
||||
|
||||
always:
|
||||
- name: Cleanup
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
Loading…
Add table
Add a link
Reference in a new issue