Last active
May 27, 2021 14:58
-
-
Save sharanpeetani/2f7a914ad918332b418bc59c7fdae3a0 to your computer and use it in GitHub Desktop.
sample playbook to update os and install docker
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
--- | |
- 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