Ansible playbook
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
- Write a Ansible Playbook to create a group called “deploy”
- name: group creation
hosts: hostserver
tasks:
- name: deploy
group:
name: deploy
state: present
- Write a Ansible Playbook to create a user called “deploy-user” which is part of group called “deploy” and with /bin/bash shell.
- name: user creation
hosts: hostserver
tasks:
- name: deploy-user
user:
name=deploy-user
groups=deploy
shell=/bin/bash
- Write a Ansible Playbook to install package named “httpd” in RHEL/centos.
- name: installinng apache on centos
hosts: web
tasks:
- name: Apache installation
ansible.builtin.yum:
name: httpd
state: latest
- Write a Ansible Playbook to start and enable the service named “httpd”
- name: Update web servers
hosts: web
tasks:
- name: Starting a Apache Server
ansible.builtin.service:
name: httpd
state: started
- Write a Ansible Playbook to create a file called “index.html” in /var/www/html with some dummy html contents.
#create a file called index.html using touch or vi
- name: file creation
hosts: web
task:
- name: creating index.html
file:
dest: /var/www/html/index.html
status:touch
- Write a Ansible Playbook to reboot a self machine.
- name: rebooting self machine
hosts: web
task:
- name: Rebooting machine
reboot:
- Write a Ansible Playbook to install a package called “git”, “wget”.
- name: To install a package "git" and "wget"
hosts: web
tasks:
- name: Install git packages
yum:
name: git
state: present
- name: Install wget packages
yum:
name: wget
state: present
- Write a Ansible Playbook to clone git repo. thttps://github.com/scmgalaxy/ansible-role-template
- name: Cloning git repo
hosts: web
environment:
http_proxy: 'http://web-proxy:8080'
https_proxy: 'http://web-proxy:8080'
tasks:
- name: cloning....
git: repo=https://github.com/scmgalaxy/ansible-role-template clone=yes dest=./ansible-role-template