mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Add new module to create/update a docker swarm. (#38280)
* Add new module to create/update a docker swarm. * Fix ansible-test sanity * Fix requirements * Fix requirements * Add tag for author * Test integration test. * Fix main.yml * Add linux arch * Add template * Fix test result * Integration test to create/remove a swarm manager * fix join test * Downgrade docker-py * fix rhel * Fix review documentation. * Fix whitespace * Check docker installation. * test docker install * check * Remove docker socket * Fix docker install * Fix sanity test * Rebase * Add docker_swarm maintainer * Fix review * Fix new version. * Add docker default values * Fix description. * Reworked documentation * Fix YAML error * Rebase * Fix example for update state. * Fix idempotent states. Fix states: present/absent. * Fix sanity * Fix variables sanity * Update example for absent state. * fix sanity * Wrap the contents of error message in to_native. Co-authored by: Dag Wieers <dag@wieers.com>
This commit is contained in:
parent
8a0a787405
commit
8b9fe42c72
8 changed files with 697 additions and 0 deletions
5
test/integration/targets/docker_swarm/aliases
Normal file
5
test/integration/targets/docker_swarm/aliases
Normal file
|
@ -0,0 +1,5 @@
|
|||
posix/ci/group2
|
||||
skip/osx
|
||||
skip/freebsd
|
||||
skip/rhel
|
||||
destructive
|
18
test/integration/targets/docker_swarm/tasks/Fedora.yml
Normal file
18
test/integration/targets/docker_swarm/tasks/Fedora.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
- name: Install Docker pre-reqs
|
||||
dnf:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
loop:
|
||||
- dnf-plugins-core
|
||||
|
||||
- name: Add repository
|
||||
command: dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
|
||||
|
||||
- name: Update cache
|
||||
command: dnf makecache
|
||||
|
||||
- name: Install docker
|
||||
dnf:
|
||||
name: docker-ce
|
||||
state: present
|
||||
enablerepo: docker-ce-test
|
11
test/integration/targets/docker_swarm/tasks/OpenSuse.yml
Normal file
11
test/integration/targets/docker_swarm/tasks/OpenSuse.yml
Normal file
|
@ -0,0 +1,11 @@
|
|||
- name: Template repo
|
||||
template:
|
||||
src: virt.repo.j2
|
||||
dest: /etc/zypp/repos.d/virt.repo
|
||||
|
||||
- name: Install docker 17
|
||||
zypper:
|
||||
name: docker>=17
|
||||
force: yes
|
||||
disable_gpg_check: yes
|
||||
update_cache: yes
|
57
test/integration/targets/docker_swarm/tasks/Ubuntu.yml
Normal file
57
test/integration/targets/docker_swarm/tasks/Ubuntu.yml
Normal file
|
@ -0,0 +1,57 @@
|
|||
- name: Get OS version
|
||||
shell: uname -r
|
||||
register: os_version
|
||||
|
||||
- name: Install packages for Trusty
|
||||
apt:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
update_cache: yes
|
||||
with_items:
|
||||
- "linux-image-extra-{{ os_version.stdout }}"
|
||||
- linux-image-extra-virtual
|
||||
when: ansible_distribution_release == 'trusty'
|
||||
|
||||
- name: Install pre-reqs
|
||||
apt:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
update_cache: yes
|
||||
with_items:
|
||||
- apt-transport-https
|
||||
- ca-certificates
|
||||
- curl
|
||||
- software-properties-common
|
||||
|
||||
- name: Add gpg key
|
||||
shell: curl -fsSL https://download.docker.com/linux/ubuntu/gpg >key && apt-key add key
|
||||
|
||||
- name: Add Docker repo
|
||||
shell: add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
||||
|
||||
- block:
|
||||
- name: Prevent service restart
|
||||
copy:
|
||||
content: exit 101
|
||||
dest: /usr/sbin/policy-rc.d
|
||||
backup: yes
|
||||
mode: 0755
|
||||
register: policy_rc_d
|
||||
|
||||
- name: Install Docker CE
|
||||
apt:
|
||||
name: docker-ce
|
||||
state: present
|
||||
update_cache: yes
|
||||
always:
|
||||
- name: Restore /usr/sbin/policy-rc.d (if needed)
|
||||
command: mv {{ policy_rc_d.backup_file }} /usr/sbin/policy-rc.d
|
||||
when:
|
||||
- "'backup_file' in policy_rc_d"
|
||||
|
||||
- name: Remove /usr/sbin/policy-rc.d (if needed)
|
||||
file:
|
||||
path: /usr/sbin/policy-rc.d
|
||||
state: absent
|
||||
when:
|
||||
- "'backup_file' not in policy_rc_d"
|
11
test/integration/targets/docker_swarm/tasks/main.yml
Normal file
11
test/integration/targets/docker_swarm/tasks/main.yml
Normal file
|
@ -0,0 +1,11 @@
|
|||
- include: Fedora.yml
|
||||
when: ansible_distribution == 'Fedora'
|
||||
|
||||
- include: OpenSuse.yml
|
||||
when: ansible_os_family == 'Suse'
|
||||
|
||||
- include: Ubuntu.yml
|
||||
when: ansible_os_family == 'Debian'
|
||||
|
||||
- include: test_swarm.yml
|
||||
when: ansible_os_family != 'RedHat' or ansible_distribution_major_version != '6'
|
68
test/integration/targets/docker_swarm/tasks/test_swarm.yml
Normal file
68
test/integration/targets/docker_swarm/tasks/test_swarm.yml
Normal file
|
@ -0,0 +1,68 @@
|
|||
- name: Install Python requirements
|
||||
pip:
|
||||
state: present
|
||||
name: "{{ item }}"
|
||||
with_items:
|
||||
- docker==2.7.0
|
||||
|
||||
- name: Test parameters with state=present
|
||||
docker_swarm:
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
|
||||
- name: assert failure when called with state=init and no advertise_addr
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "advertise_addr is required to initialize a swarm cluster."'
|
||||
|
||||
- name: Test parameters with state=join
|
||||
docker_swarm:
|
||||
state: join
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
|
||||
- name: assert failure when called with state=join and no advertise_addr,remote_addrs,join_token
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "state is join but all of the following are missing: advertise_addr, remote_addrs, join_token"'
|
||||
|
||||
- name: Test parameters with state=remove
|
||||
docker_swarm:
|
||||
state: remove
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
|
||||
- name: assert failure when called with state=remove and no node_id
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "state is remove but all of the following are missing: node_id"'
|
||||
|
||||
- name: Create a Swarm cluster
|
||||
docker_swarm:
|
||||
state: present
|
||||
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||
register: output
|
||||
|
||||
- name: assert changed when create a new swarm cluster
|
||||
assert:
|
||||
that:
|
||||
- 'output.changed'
|
||||
- 'output.actions[0] | regex_search("New Swarm cluster created: ")'
|
||||
- 'output.swarm_facts.JoinTokens.Manager'
|
||||
- 'output.swarm_facts.JoinTokens.Worker'
|
||||
|
||||
- name: Remove a Swarm cluster
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
register: output
|
||||
|
||||
- name: assert changed when remove a swarm cluster
|
||||
assert:
|
||||
that:
|
||||
- 'output.changed'
|
||||
- 'output.actions[0] == "Node has leaved the swarm cluster"'
|
|
@ -0,0 +1,7 @@
|
|||
[Virtualization_containers]
|
||||
name=Virtualization:containers (openSUSE_Leap_{{ ansible_distribution_version }})
|
||||
type=rpm-md
|
||||
baseurl=http://download.opensuse.org/repositories/Virtualization:/containers/openSUSE_Leap_{{ ansible_distribution_version }}/
|
||||
gpgcheck=1
|
||||
gpgkey=http://download.opensuse.org/repositories/Virtualization:/containers/openSUSE_Leap_{{ ansible_distribution_version }}/repodata/repomd.xml.key
|
||||
enabled=1
|
Loading…
Add table
Add a link
Reference in a new issue