Last active
February 5, 2019 07:59
-
-
Save boonchu/bcb909bfad8b0db728ffbec3a88e49c1 to your computer and use it in GitHub Desktop.
docker_ansible_playbook
This file contains 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: localhost | |
connection: local | |
gather_facts: True | |
become_user: root | |
become: yes | |
gather_subset: | |
- lsb | |
- user | |
tasks: | |
- name: Installing apt packages. | |
apt: | |
name: "{{ item }}" | |
state: installed | |
with_items: | |
- htop | |
- ctop | |
- tmux | |
- unzip | |
- mtr | |
- bash-completion | |
- tree | |
- colordiff | |
- ntp | |
- bwm-ng | |
- jq | |
- curl | |
- apt-transport-https | |
- ca-certificates | |
- gnupg-agent | |
- software-properties-common | |
- docker-compose | |
- name: Installing GPG docker source repository key. | |
shell: curl -s -S -L https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
ignore_errors: yes | |
- name: Adding deb repository. | |
command: sudo touch /etc/apt/sources.list.d/docker-ce.list | |
- name: Appending inline string to /etc/apt/sources.list.d/docker-ce.list. | |
lineinfile: | |
dest: "/etc/apt/sources.list.d/docker-ce.list" | |
line: "{{ item }}" | |
with_items: | |
- deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_facts['lsb']['codename'] }} stable | |
- name: Updating apt. | |
apt: | |
update_cache: yes | |
- name: Installing docker engine. | |
apt: | |
name: "{{ item }}" | |
state: present | |
with_items: | |
- docker-ce | |
- docker-ce-cli | |
- containerd.io | |
- name: Adding user {{ ansible_facts['user_id'] }} to docker group. | |
command: sudo usermod -aG docker {{ ansible_facts['user_id'] }} | |
- name: Updating apt. | |
apt: | |
update_cache: yes | |
- name: Docker run even after restart | |
command: sudo docker run -dit --restart unless-stopped -p 80:8080 boonchu/node-web-app | |
ignore_errors: yes | |
- name: Pause for 1 minutes for application startup. | |
pause: | |
minutes: 1 | |
- name: Is Docker Running? | |
command: curl localhost:8080/books | |
register: out | |
- debug: var=out.stdout_lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment