Skip to content

Instantly share code, notes, and snippets.

@sharanpeetani
Last active May 27, 2021 14:58
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 sharanpeetani/2f7a914ad918332b418bc59c7fdae3a0 to your computer and use it in GitHub Desktop.
Save sharanpeetani/2f7a914ad918332b418bc59c7fdae3a0 to your computer and use it in GitHub Desktop.
sample playbook to update os and install docker
---
- name: OS update and install docker
hosts: localhost
become: yes
tasks:
- name: Remove useless packages from the cache
apt:
autoclean: yes
- name: remove unrequired packages
apt:
autoremove: yes
- name: Upgrade all packages on servers
apt:
upgrade: dist
force_apt_get: yes
update_cache: yes
cache_valid_time: 600
- name: Disable SWAP
shell: swapoff -a
- name: Disable SWAP in fstab
replace:
path: /etc/fstab
regexp: '^([^#].*?\sswap\s+sw\s+.*)$'
replace: '# \1'
- name: Install required system packages
apt:
name: "{{ item }}"
state: latest
update_cache: yes
loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'software-properties-common', 'nfs-common']
- 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 bionic stable
state: present
- name: Update apt and install docker-ce
apt:
update_cache: yes
name: docker-ce
state: latest
- name: enable and start docker service
systemd:
name: docker
daemon_reload: true
enabled: yes
masked: no
state: restarted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment