Docker
Docker
yaml
---
- name: Installing Docker Engine
hosts: all
become: true
tasks:
#sudo apt-get update
- name: updating the machine
apt:
update_cache: yes
#sudo apt-get install ca-certificates curl gnupg
- name: Installing ca-certificates, curl, gnupg
apt:
name:
- ca-certificates
- curl
- gnupg
#sudo install -m 0755 -d /etc/apt/keyrings
- name: Create a directory for Docker keys
file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
#curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o
/etc/apt/keyrings/docker.gpg
- name: Download and install the GPG key for Docker
shell: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --
dearmor -o /etc/apt/keyrings/docker.gpg
#sudo chmod a+r /etc/apt/keyrings/docker.gpg
- name: Changing permissions for DockerGPG keys
file:
path: /etc/apt/keyrings/docker.gpg
mode: '0644'
#echo \
# "deb [arch="$(dpkg --print-architecture)"
signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
# "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
# sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
#sudo apt-get update
- name: Add the repository to the apt sources
shell: echo "deb [arch="$(dpkg --print-architecture)"
signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | sudo tee
/etc/apt/sources.list.d/docker.list > /dev/null
#sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin
docker-compose-plugin
- name: Installing docker and its dependencies
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
update_cache: yes
state: latest
---
- name: Creating apache2 and nginx containers
hosts: all
become: true
tasks:
- community.docker.docker_container:
name: "apache-container"
image: "ubuntu/apache2"
detach: yes
state: started
publish_all_ports: yes
- community.docker.docker_container:
name: "nginxcontainer"
image: "nginx"
detach: yes
state: started
publish_all_ports: yes
---
- name: Pulling apache2 and nginx images from DockerHub
hosts: all
become: true
tasks:
- community.docker.docker_image:
name: "ubuntu/apache2"
source: pull
- community.docker.docker_image:
name: "nginx"
source: pull