From 0fa2ed983e22c312821fe5eb0ca4f0779486f3d5 Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Wed, 3 May 2023 14:01:41 +0200 Subject: [PATCH] Add autoinstall docker --- playbook.yml | 5 ++--- roles/docker/tasks/base.yml | 2 -- roles/docker/tasks/install.yml | 36 ++++++++++++++++++++++++++++++++++ roles/docker/tasks/main.yml | 6 +++--- 4 files changed, 41 insertions(+), 8 deletions(-) delete mode 100644 roles/docker/tasks/base.yml create mode 100644 roles/docker/tasks/install.yml diff --git a/playbook.yml b/playbook.yml index 655217e..7880017 100644 --- a/playbook.yml +++ b/playbook.yml @@ -1,7 +1,6 @@ --- - name: Install servers - hosts: servers - become: true + hosts: all roles: - - { role: docker, tags: ['docker'] } \ No newline at end of file + - { role: docker, tags: ["docker"] } diff --git a/roles/docker/tasks/base.yml b/roles/docker/tasks/base.yml deleted file mode 100644 index cd21505..0000000 --- a/roles/docker/tasks/base.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- - diff --git a/roles/docker/tasks/install.yml b/roles/docker/tasks/install.yml new file mode 100644 index 0000000..8c62c20 --- /dev/null +++ b/roles/docker/tasks/install.yml @@ -0,0 +1,36 @@ +--- +- name: set mydistribution + ansible.builtin.set_fact: + mydistribution: "{{ 'rhel' if (ansible_distribution == 'Red Hat Enterprise Linux') else (ansible_distribution | lower) }}" + +- name: Add signing key + ansible.builtin.rpm_key: + key: "https://download.docker.com/linux/{{ mydistribution }}/gpg" + state: present + +- name: Add repository into repo.d list + ansible.builtin.yum_repository: + name: docker + description: docker repository + baseurl: "https://download.docker.com/linux/{{ mydistribution }}/$releasever/$basearch/stable" + enabled: true + gpgcheck: true + gpgkey: "https://download.docker.com/linux/{{ mydistribution }}/gpg" + +- name: Install Docker + ansible.builtin.yum: + name: + - docker-ce + - docker-ce-cli + - containerd.io + - docker-buildx-plugin + - docker-compose-plugin + state: latest + update_cache: true + +- name: Start Docker + ansible.builtin.service: + name: "docker" + enabled: true + state: started + ignore_errors: true # TODO: Remove it (Not work in docker container) diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml index 3f670ac..ff8f890 100644 --- a/roles/docker/tasks/main.yml +++ b/roles/docker/tasks/main.yml @@ -1,4 +1,4 @@ --- - -- ansible.builtin.import_tasks: base.yml - name: base \ No newline at end of file +- ansible.builtin.import_tasks: install.yml + name: base + become: true