GithubHelp home page GithubHelp logo

karvounis / ansible-docker-swarm-management-role Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 12 KB

Ansible role that manages Docker Swarm stacks, volumes, configs, networks and secrets

License: MIT License

Ruby 100.00%
docker docker-swarm ansible ansible-role ansible-galaxy ansible-roles cluster orchestration automation

ansible-docker-swarm-management-role's Introduction

Ansible Role: Docker Swarm Management

This Ansible role manages Docker Swarm stacks, volumes, configs, networks and secrets.

Requirements

We are using the pre-commit tool in order to perform some checks on the committed files. Make sure to execute pre-commit install before contributing to this repo!

Role Variables

  1. docker_networks: List of Docker network objects. Defaults to [].
  2. docker_volumes: List of Docker volume objects. Defaults to [].
  3. docker_configs: List of Docker config objects. Defaults to [].
  4. docker_configs_no_log: Flag that defines whether or not Ansible logs the configs result. Defaults to true.
  5. docker_secrets: List of Docker secret objects. Defaults to [].
  6. docker_secrets_no_log: Flag that defines whether or not Ansible logs the secrets result. Defaults to true.
  7. docker_stacks: List of Docker secret objects. Defaults to [].

Dependencies

Collections

Install them by executing ansible-galaxy install -r requirements.yml.

Example variables

docker_networks:
  - name: network_one
    state: present
    driver: overlay
  - name: network_two
    ipam_config:
      - subnet: 172.3.27.0/24
        gateway: 172.3.27.2
        iprange: 172.3.27.0/26
        aux_addresses:
          host1: 172.3.27.3
          host2: 172.3.27.4
  - name: network_three
    state: absent
    force: yes
  - name: network_four
    labels:
      key1: value1
      key2: value2

docker_volumes:
  - name: volume_one
    state: present
  - name: volume_two
    labels:
      key1: value1
      key2: value2
    driver_options:
      type: btrfs
      device: /dev/sda2
  - name: volume_three
    state: absent

docker_secrets:
  - name: foo
    # If the file is JSON or binary, Ansible might modify it (because
    # it is first decoded and later re-encoded). Base64-encoding the
    # file directly after reading it prevents this to happen.
    data: "{{ lookup('file', '/path/to/secret/file') | b64encode }}"
    data_is_b64: true
    state: present
    # Force the removal/creation of the secret
  - name: foo
    data: Goodnight everyone!
    force: yes
    state: present
    # Remove secret foo
  - name: foo
    state: absent

docker_configs:
  - name: config_one
    data: |
      mongo:
        dsn: mongodb://admin:[email protected]/admin
        database_name: db
      health-check-endpoint: /healthcheck
      service-port: 9999
  - name: config_two
    data: "{{ lookup('template', 'path_to_config_two_template.yaml') }}"
  - name: config_three
    data: "{{ lookup('file', 'path_to_config_three_file.yaml') }}"

docker_stacks:
  # Deploy stack from a compose file. You can use here the lookup function
  - name: stack_one
    state: present
    compose:
      - /opt/stack_one.yml
  # Deploy stack from base compose file and override the web service
  - name: stack_two
    state: present
    compose:
      - /opt/stack_two.yml
      - version: '3'
        services:
          web:
            image: nginx:latest
            environment:
              ENVVAR: envvar
  # Remove stack
  - name: stack_three
    state: absent
  # Deploy stack from a j2 compose file
  - name: stack_four
    state: present
    compose:
      - "{{ lookup('template', 'path_to_stack_four_template_file.yml.j2') | from_yaml }}"

Advanced examples

You can find an advanced tutorial in the repo https://github.com/karvounis/ansible-docker-swarm-management-role-example.

License

MIT

Author Information

This role was created in 2021 by Evangelos Karvounis.

ansible-docker-swarm-management-role's People

Contributors

karvounis avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.