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.pip
- geerlingguy.docker - geerlingguy.docker
``` ```
## About Amazon Linux
Installation of docker-ce comes from amazon-linux-extras packages
## Dependencies ## Dependencies

View File

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

View File

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