2019年11月29日金曜日

AnsibleでDocker/docker-composeをインストールする

以下のAnsibleのRoleを使用して、Dockerとdocker-composeをインストールする事ができます。

roles/docker_compose/tasks/main.yml
---
- name: uninstall old packages
  apt:
    name: "{{ packages }}"
    state: absent
  vars:
    packages:
    - docker
    - docker-engine
    - docker.io
    - containerd
    - runc
  become: true

- name: install required packages
  apt:
    name: "{{ packages }}"
    state: latest
    update_cache: yes
  vars:
    packages:
    - apt-transport-https
    - ca-certificates
    - curl
    - software-properties-common
    - virtualenv
    - python3-setuptools
  become: true

- name: add a key for docker
  apt_key:
    url: https://download.docker.com/linux/ubuntu/gpg
    state: present
  become: true

- name: add a repository
  apt_repository:
    repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
    state: present
  become: true

- name: install docker
  apt:
    name: "{{ packages }}"
    state: latest
    update_cache: yes
  vars:
    packages:
    - docker-ce
    - docker-ce-cli
    - containerd.io
  become: true

- name: enable docker
  systemd:
    name: docker
    state: started
    enabled: yes
  become: true

- name: check whther docker-compose exists
  stat:
    path: "/usr/local/bin/docker-compose"
  register: chk_docker_compose

- name: download docker-compose
  get_url:
    url: https://github.com/docker/compose/releases/download/1.24.1/docker-compose-Linux-x86_64
    dest: /usr/local/bin/docker-compose
  when: chk_docker_compose.stat.exists == false
  become: true

- name:  adding "+x"
  file: dest=/usr/local/bin/docker-compose mode=a+x
  when: chk_docker_compose.stat.exists == false
  become: true

0 件のコメント:

コメントを投稿