Last active
November 19, 2021 22:23
-
-
Save mansurali901/085f8c5ab5deb39189a251822ead7128 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: all | |
become: true | |
vars: | |
create_containers: 4 | |
default_container_name: docker | |
default_container_image: nginx | |
default_container_command: sleep 1d | |
default_container_port: 8080 | |
defaul_host_port: 8080 | |
tasks: | |
- name: Install aptitude using apt | |
apt: name=aptitude state=latest update_cache=yes force_apt_get=yes | |
- name: Install required system packages | |
apt: name={{ item }} state=latest update_cache=yes | |
loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'software-properties-common', 'python3-pip', 'virtualenv', 'python3-setuptools'] | |
- name: Add Docker GPG apt Key | |
apt_key: | |
url: https://download.docker.com/linux/ubuntu/gpg | |
state: present | |
- name: Add Docker Repository | |
apt_repository: | |
repo: deb https://download.docker.com/linux/ubuntu xenial stable | |
state: present | |
- name: Update apt and install docker-ce | |
apt: update_cache=yes name=docker-ce state=latest | |
- name: Install Docker Module for Python | |
pip: | |
name: docker | |
- name: Pull default Docker image | |
docker_image: | |
name: "{{ default_container_image }}" | |
source: pull | |
- name: Create default containers | |
docker_container: | |
name: "{{ default_container_name }}{{ item }}" | |
image: "{{ default_container_image }}" | |
command: "{{ default_container_command }}" | |
state: present | |
published_ports: | |
- "{{ defaul_host_port }}":"{{ default_container_port }}"8080 | |
with_sequence: count={{ create_containers }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment