--- - name: "Install docker" hosts: target tasks: - name: "Install kernel extras" apt: pkg: "{{ item }}" state: present with_items: - "linux-image-extra-{{ ansible_kernel }}" - linux-image-extra-virtual - apt-transport-https - ca-certificates - software-properties-common when: ansible_distribution == "Ubuntu" - name: "Install docker apt key" shell: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - when: ansible_distribution == "Ubuntu" - name: "Configure docker.list" copy: src: "../files/{{ item }}" dest: "/etc/apt/sources.list.d/{{ item }}" mode: 0644 owner: root group: root with_items: - docker.list when: ansible_distribution == "Ubuntu" - name: "Update apt" apt: update_cache: yes when: ansible_distribution == "Ubuntu" - name: "Install docker packages" apt: pkg: "{{ item }}" state: present with_items: - docker-ce when: ansible_distribution == "Ubuntu" - name: "Install required packages" yum: name: "{{ item }}" state: present with_items: - yum-utils - device-mapper-persistent-data - lvm2 when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" - name: "Add docker repository" shell: yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" - name: "Update yum cache" yum: update_cache: yes when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" - name: "Install required packages" yum: name: "{{ item }}" state: present with_items: - docker-ce when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" - name: "Install docker" portage: package: "{{ item }}" update: yes changed_use: yes with_items: - app-emulation/docker when: ansible_distribution == "Gentoo" - name: "Enable docker" service: name: "{{ item.name }}" enabled: yes state: started runlevel: "{{ item.runlevel }}" with_items: - { name: docker, runlevel: default }