Skip to content

Instantly share code, notes, and snippets.

@awadhwana
Created February 25, 2020 13:30
Show Gist options
  • Save awadhwana/aaac1abe5eee919b93e1b85980c1497d to your computer and use it in GitHub Desktop.
Save awadhwana/aaac1abe5eee919b93e1b85980c1497d to your computer and use it in GitHub Desktop.
Ansible script to install docker on EC2 instance
[ec2]
*instance ip address* ansible_user=ubuntu ansible_python_interpreter=/usr/bin/python3
- name: Configure EC2 instance
hosts: ec2
connection: ssh
become: yes
tasks:
- name: Update the machine
command: sudo apt clean && update -y
- name: Install basic list of packages
apt:
name: ['apt-transport-https','ca-certificates','curl','gnupg2','software-properties-common']
state: present
update_cache: no
- name: Add Docker GPG apt Key
apt_key: url=https://download.docker.com/linux/ubuntu/gpg
- name: Add Docker Repository
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ansible_distribution_release}} stable
- name: Install Docker packages
apt:
name: ['docker-ce','docker-ce-cli','containerd.io']
state: present
#TO RUN
# create a file called host and add your host ip address
#ansible-playbook -i host docker.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment