mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Add docker_config module (#38792)
* Add docker_config module * Address review comments * Merge description lines * Stop returning empty config_id in results * Add integration tests for docker_config Based on docker_secret's tests. * Ensure swarm using docker_swarm module * Add minimum docker / docker api version requirements ref: https://github.com/ansible/ansible/pull/47046 * Check Docker API version before running tests ref: https://github.com/ansible/ansible/pull/47340 * Typo * Wording * Improve example * Assert state == absent is idempotent
This commit is contained in:
4
test/integration/targets/docker_config/aliases
Normal file
4
test/integration/targets/docker_config/aliases
Normal file
@@ -0,0 +1,4 @@
|
||||
shippable/posix/group2
|
||||
skip/osx
|
||||
skip/freebsd
|
||||
destructive
|
||||
3
test/integration/targets/docker_config/meta/main.yml
Normal file
3
test/integration/targets/docker_config/meta/main.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
dependencies:
|
||||
- setup_docker
|
||||
7
test/integration/targets/docker_config/tasks/main.yml
Normal file
7
test/integration/targets/docker_config/tasks/main.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
- name: Check Docker API version
|
||||
command: "{{ ansible_python.executable }} -c 'import docker; print(docker.from_env().version()[\"ApiVersion\"])'"
|
||||
register: docker_api_version
|
||||
ignore_errors: yes
|
||||
|
||||
- include_tasks: test_docker_config.yml
|
||||
when: docker_api_version.rc == 0 and docker_api_version.stdout is version('1.30', '>=')
|
||||
@@ -0,0 +1,113 @@
|
||||
- name: Make sure we're not already using Docker swarm
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
|
||||
- name: Create a Swarm cluster
|
||||
docker_swarm:
|
||||
state: present
|
||||
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||
|
||||
- name: Parameter name should be required
|
||||
docker_config:
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
|
||||
- name: assert failure when called with no name
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "missing required arguments: name"'
|
||||
|
||||
- name: Test parameters
|
||||
docker_config:
|
||||
name: foo
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
|
||||
- name: assert failure when called with no data
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "state is present but all of the following are missing: data"'
|
||||
|
||||
- name: Create config
|
||||
docker_config:
|
||||
name: db_password
|
||||
data: opensesame!
|
||||
state: present
|
||||
register: output
|
||||
|
||||
- name: Create variable config_id
|
||||
set_fact:
|
||||
config_id: "{{ output.config_id }}"
|
||||
|
||||
- name: Inspect config
|
||||
command: "docker config inspect {{ config_id }}"
|
||||
register: inspect
|
||||
|
||||
- debug: var=inspect
|
||||
|
||||
- name: assert config creation succeeded
|
||||
assert:
|
||||
that:
|
||||
- "'db_password' in inspect.stdout"
|
||||
- "'ansible_key' in inspect.stdout"
|
||||
|
||||
- name: Create config again
|
||||
docker_config:
|
||||
name: db_password
|
||||
data: opensesame!
|
||||
state: present
|
||||
register: output
|
||||
|
||||
- name: assert create config is idempotent
|
||||
assert:
|
||||
that:
|
||||
- not output.changed
|
||||
|
||||
- name: Update config
|
||||
docker_config:
|
||||
name: db_password
|
||||
data: newpassword!
|
||||
state: present
|
||||
register: output
|
||||
|
||||
- name: assert config was updated
|
||||
assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.config_id != config_id
|
||||
|
||||
- name: Remove config
|
||||
docker_config:
|
||||
name: db_password
|
||||
state: absent
|
||||
|
||||
- name: Check that config is removed
|
||||
command: "docker config inspect {{ config_id }}"
|
||||
register: output
|
||||
ignore_errors: yes
|
||||
|
||||
- name: assert config was removed
|
||||
assert:
|
||||
that:
|
||||
- output.failed
|
||||
|
||||
- name: Remove config
|
||||
docker_config:
|
||||
name: db_password
|
||||
state: absent
|
||||
register: output
|
||||
|
||||
- name: assert remove config is idempotent
|
||||
assert:
|
||||
that:
|
||||
- not output.changed
|
||||
|
||||
- name: Remove a Swarm cluster
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
Reference in New Issue
Block a user