--- - name: Configure docker hosts hosts: servers roles: - role: docker tasks: - name: Allow swarm traffic through the firewall become: true firewalld: state: enabled service: docker-swarm zone: public permanent: true immediate: true - name: Disable firewall on docker bridge interface become: true firewalld: state: enabled interface: docker0 zone: trusted permanent: true immediate: true - name: Configure swarm master hosts: jupiter tasks: - name: Configure portainer volume docker_volume: volume_name: portainer - name: Run portainer docker_container: name: omni.portainer image: portainer/portainer restart_policy: unless-stopped published_ports: - 0.0.0.0:8000:8000 - 0.0.0.0:9000:9000 volumes: - /var/run/docker.sock:/var/run/docker.sock - portainer:/data - name: Initialize swarm docker_swarm: state: present advertise_addr: "{{ omni_docker_swarm_iface }}" - name: Set swarm master to DRAIN docker_node: hostname: "{{ ansible_host }}" availability: drain - name: Configure swarm nodes hosts: - remus - romulus tags: docker-nodes tasks: - name: Fetch docker swarm information delegate_to: jupiter docker_swarm_info: register: _swarm_info - name: Join workers to swarm docker_swarm: state: join remote_addrs: ["jupiter.svr.local"] join_token: "{{ _swarm_info.swarm_facts.JoinTokens.Worker }}" advertise_addr: "{{ omni_docker_swarm_iface }}"