From 58470c2fb9ee693903f75752c51147eda236a4d5 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sun, 24 Nov 2019 17:21:18 +0100 Subject: [PATCH] refactoring and cleanup --- .gitignore | 2 +- defaults/main.yml | 8 +++++++- handlers/main.yml | 4 ++-- tasks/{setup.yml => config.yml} | 24 +++--------------------- tasks/install.yml | 30 ++++++++++++++++++++++++++++++ tasks/main.yml | 3 ++- vars/main.yml | 5 ----- 7 files changed, 45 insertions(+), 31 deletions(-) rename tasks/{setup.yml => config.yml} (75%) create mode 100644 tasks/install.yml delete mode 100644 vars/main.yml diff --git a/.gitignore b/.gitignore index 5becda8..d97b7cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # ---> Ansible *.retry -filter/plugins/ +plugins library # ---> Python diff --git a/defaults/main.yml b/defaults/main.yml index 6025f4c..a1a79de 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,6 @@ --- -dockerengine_package: docker +dockerengine_packages: + - docker # @var dockerengine_packages_extra:description: > # The role requires epel repository and pip to work .You can use @@ -8,6 +9,11 @@ dockerengine_package: docker # @var dockerengine_packages_extra:example: $ ["epel-release", "python2-pip"] dockerengine_packages_extra: [] +dockerengine_packages_python: + - name: docker-compose + +dockerengine_service: docker + dockerengine_docker_group_enabled: False dockerengine_secure_registries: [] dockerengine_insecure_registries: [] diff --git a/handlers/main.yml b/handlers/main.yml index 0d8edbe..d3cfcd4 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,8 +1,8 @@ --- - name: Restart docker engine - systemd: + service: state: restarted - name: "{{ dockerengine_package }}" + name: "{{ dockerengine_service }}" daemon_reload: yes enabled: yes listen: __docker_restart diff --git a/tasks/setup.yml b/tasks/config.yml similarity index 75% rename from tasks/setup.yml rename to tasks/config.yml index b9c5e9c..cf97b51 100644 --- a/tasks/setup.yml +++ b/tasks/config.yml @@ -1,23 +1,5 @@ --- - block: - - name: Install docker engine - package: - name: "{{ dockerengine_package }}" - state: present - - - name: Install dependencies - package: - name: "{{ item }}" - state: present - loop: "{{ dockerengine_packages_extra }}" - - - name: Install python requirements - pip: - name: "{{ item.name }}" - executable: "{{ item.exec | default(omit) }}" - state: present - loop: "{{ __docker_python_requirements }}" - - name: Add docker group group: name: docker @@ -33,8 +15,8 @@ group: root mode: 0644 loop: - - { src: 'etc/sysconfig/docker.j2', dest: '/etc/sysconfig/{{ dockerengine_package }}' } - - { src: 'etc/sysconfig/docker-storage-setup.j2', dest: '/etc/sysconfig/{{ dockerengine_package }}-storage-setup' } + - { src: 'etc/sysconfig/docker.j2', dest: '/etc/sysconfig/{{ dockerengine_service }}' } + - { src: 'etc/sysconfig/docker-storage-setup.j2', dest: '/etc/sysconfig/{{ dockerengine_service }}-storage-setup' } - { src: 'etc/containers/registries.conf.j2', dest: '/etc/containers/registries.conf' } loop_control: label: "{{ item.dest }}" @@ -71,7 +53,7 @@ - name: Ensure docker engine is up and running service: - name: "{{ dockerengine_package }}" + name: "{{ dockerengine_service }}" enabled: True state: started become: True diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..a21a587 --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,30 @@ +--- +- block: + - name: Install dependencies + package: + name: "{{ item }}" + state: present + loop: "{{ dockerengine_packages_extra }}" + + - name: Install packages + package: + name: "{{ dockerengine_packages }}" + state: present + + - name: Install python packages + pip: + name: "{{ item.name }}" + executable: "{{ item.exec | default('/usr/bin/pip3') }}" + state: present + loop: "{{ dockerengine_packages_python }}" + loop_control: + label: "{{ item.name }}" + become: True + become_user: root + +- name: Install ansible requirements + pip: + name: "{{ item }}" + state: present + loop: + - docker diff --git a/tasks/main.yml b/tasks/main.yml index 1f69f7a..1869ca1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,3 @@ --- -- include_tasks: setup.yml +- include_tasks: install.yml +- include_tasks: config.yml diff --git a/vars/main.yml b/vars/main.yml deleted file mode 100644 index dcbd206..0000000 --- a/vars/main.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -__docker_python_requirements: - - name: docker - - name: docker-compose - exec: /usr/bin/pip3