Add possibility to install docker to Amazon Linux

This commit is contained in:
khismatullinmax 2023-03-12 21:03:10 +01:00
parent 67e50e9af0
commit 969241843a
5 changed files with 69 additions and 31 deletions

View File

@ -104,6 +104,9 @@ Many users of this role wish to also use Ansible to then _build_ Docker images a
- geerlingguy.pip
- geerlingguy.docker
```
## About Amazon Linux
Installation of docker-ce comes from amazon-linux-extras packages
## Dependencies

View File

@ -31,6 +31,9 @@ galaxy_info:
- name: ArchLinux
versions:
- all
- name: Amazon
versions:
- 2
galaxy_tags:
- web
- system

View File

@ -11,44 +11,51 @@
- 'vars'
- include_tasks: setup-RedHat.yml
when: ansible_os_family == 'RedHat'
when: ansible_os_family == 'RedHat' and ansible_distribution != 'Amazon'
- include_tasks: setup-Amazon.yml
when: ansible_distribution == 'Amazon'
- include_tasks: setup-Debian.yml
when: ansible_os_family == 'Debian'
- name: Install Docker packages.
package:
name: "{{ docker_packages }}"
state: "{{ docker_packages_state }}"
notify: restart docker
ignore_errors: "{{ ansible_check_mode }}"
when: "ansible_version.full is version_compare('2.12', '<') or ansible_os_family not in ['RedHat', 'Debian']"
- block:
- name: Install Docker packages (with downgrade option).
package:
name: "{{ docker_packages }}"
state: "{{ docker_packages_state }}"
allow_downgrade: true
notify: restart docker
ignore_errors: "{{ ansible_check_mode }}"
when: "ansible_version.full is version_compare('2.12', '>=') and ansible_os_family in ['RedHat', 'Debian']"
- name: Install Docker packages.
package:
name: "{{ docker_packages }}"
state: "{{ docker_packages_state }}"
notify: restart docker
ignore_errors: "{{ ansible_check_mode }}"
when: "ansible_version.full is version_compare('2.12', '<') or ansible_os_family not in ['RedHat', 'Debian']"
- name: Install docker-compose plugin.
package:
name: "{{ docker_compose_package }}"
state: "{{ docker_compose_package_state }}"
notify: restart docker
ignore_errors: "{{ ansible_check_mode }}"
when: "docker_install_compose_plugin | bool == true and (ansible_version.full is version_compare('2.12', '<') or ansible_os_family not in ['RedHat', 'Debian'])"
- name: Install Docker packages (with downgrade option).
package:
name: "{{ docker_packages }}"
state: "{{ docker_packages_state }}"
allow_downgrade: true
notify: restart docker
ignore_errors: "{{ ansible_check_mode }}"
when: "ansible_version.full is version_compare('2.12', '>=') and ansible_os_family in ['RedHat', 'Debian']"
- name: Install docker-compose-plugin (with downgrade option).
package:
name: "{{ docker_compose_package }}"
state: "{{ docker_compose_package_state }}"
allow_downgrade: true
notify: restart docker
ignore_errors: "{{ ansible_check_mode }}"
when: "docker_install_compose_plugin | bool == true and ansible_version.full is version_compare('2.12', '>=') and ansible_os_family in ['RedHat', 'Debian']"
- name: Install docker-compose plugin.
package:
name: "{{ docker_compose_package }}"
state: "{{ docker_compose_package_state }}"
notify: restart docker
ignore_errors: "{{ ansible_check_mode }}"
when: "docker_install_compose_plugin | bool == true and (ansible_version.full is version_compare('2.12', '<') or ansible_os_family not in ['RedHat', 'Debian'])"
- name: Install docker-compose-plugin (with downgrade option).
package:
name: "{{ docker_compose_package }}"
state: "{{ docker_compose_package_state }}"
allow_downgrade: true
notify: restart docker
ignore_errors: "{{ ansible_check_mode }}"
when: "docker_install_compose_plugin | bool == true and ansible_version.full is version_compare('2.12', '>=') and ansible_os_family in ['RedHat', 'Debian']"
when: ansible_distribution != 'Amazon'
- name: Ensure /etc/docker/ directory exists.
file:

23
tasks/setup-Amazon.yml Normal file
View File

@ -0,0 +1,23 @@
---
- name: Ensure a list of yum packages are installed on Amazon Linux
package:
name: "{{ packages }}"
state: present
vars:
packages:
- python-pip
- yum-utils
- device-mapper-persistent-data
- lvm2
- amazon-linux-extras
- name: Add extras repository
command: yum-config-manager --enable extras
register: yum_config_manager_output
changed_when: yum_config_manager_output.rc != 0
- name: Install docker-ce from amazon-linux-extras packages
package:
name: "{{ docker_packages }}"
state: "{{ docker_packages_state }}"
notify: restart docker

2
vars/Amazon.yml Normal file
View File

@ -0,0 +1,2 @@
---
docker_packages: "docker"