Ansible Playbooks

These simple playbooks can get you started with Ansible.

Fri Sep 16, 2022

Ansible Playbooks By #TrainWithShubham

Update all the Servers

ansible all -m apt -a "upgrade=yes update_cache=yes cache_valid_time=86400" --become

Creating a File

ubuntu@ip-172-31-91-124:~/ansible/playbooks$ cat create_file.yml
---
- name: This playbook will create a file
hosts: all
become: true
tasks:
- name: creating a file
file:
path: /home/ubuntu/testdemo2.txt
state: touch

Creating a User

ubuntu@ip-172-31-91-124:~/ansible/playbooks$ cat create_user.yml
---
- name: This Playbook will create a user
hosts: all
become: true
tasks:
- name: Create a user Shubham
user: name=shubham

Installing Docker

ubuntu@ip-172-31-91-124:~/ansible/playbooks$ cat install_docker.yml

---
- name: This playbook will install Docker
hosts: all
become: true
tasks:
- 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 focal stable
state: present
- name: Install Docker
apt:
name: docker-ce
state: latest

Shubham Londhe
Checkout the courses