Skip to content

Instantly share code, notes, and snippets.

@vagnernogueira
Created May 7, 2022 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vagnernogueira/55f95440a1623de5790caf08c3b17571 to your computer and use it in GitHub Desktop.
Save vagnernogueira/55f95440a1623de5790caf08c3b17571 to your computer and use it in GitHub Desktop.
Ansible Playbooks
---
# Instalação do docker em distro Ubuntu no WSL 2
# Use
# sudo ansible-playbook install-docker.yml
# Referências
# (1) https://github.com/codeedu/wsl2-docker-quickstart#docker-engine-docker-nativo-diretamente-instalado-no-wsl2
# (2) https://cloudinfrastructureservices.co.uk/how-to-install-docker-compose-using-ansible-playbook/
- hosts: localhost
#become: true
#become_user: root
tasks:
- name: Install apt-transport-https
apt:
name: ['apt-transport-https','ca-certificates', 'lsb-release', 'gnupg','curl']
state: latest
update_cache: true
- name: Add signing key
apt_key:
url: "https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg"
keyring: /usr/share/keyrings/docker-archive-keyring.gpg
state: present
- name: Add repository into sources list
apt_repository:
repo: "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable"
state: present
filename: docker
- name: Install Docker
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
state: latest
update_cache: true
- name: Add "vagner" user to "docker" group
remote_user: vagner
user:
name: "vagner"
group: "docker"
append: yes
- name: Install docker-compose from official github repo
remote_user: vagner
get_url:
url : https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-x86_64
dest: /usr/local/bin/docker-compose
mode: 'u+x,g+x'
force: yes
- name: Link docker-compose
file:
src: "/usr/local/bin/docker-compose"
dest: "/usr/bin/docker-compose"
state: link
---
# Atualização da distro Ubuntu no WSL 2
# Use
# sudo ansible-playbook update-ubuntu.yml
- hosts: localhost
#become: true
#become_user: root
tasks:
- name: Update apt repo and cache
apt: update_cache=yes force_apt_get=yes cache_valid_time=3600
- name: Upgrade all packages
apt: upgrade=dist force_apt_get=yes
- name: Check if a reboot is needed
register: reboot_required_file
stat: path=/var/run/reboot-required get_md5=no
- name: Show reboot message
debug:
msg: "Rebook necessario!"
when: reboot_required_file.stat.exists
- name: Show final message
debug:
msg: "Update finish!"
when: not reboot_required_file.stat.exists
#- name: Reboot the box if kernel updated
# reboot:
# msg: "Reboot initiated by Ansible for kernel updates"
# connect_timeout: 5
# reboot_timeout: 300
# pre_reboot_delay: 0
# post_reboot_delay: 30
# test_command: uptime
# when: reboot_required_file.stat.exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment