
Execution Mode – Remote
-
Write a Ansible Playbook to create a group called “deploy”
-
Write a Ansible Playbook to create a user called “deploy-user” which is part of group called “deploy” and with /bin/bash shell.
-
Write a Ansible Playbook to install package named “httpd” in RHEL/centos.
-
Write a Ansible Playbook to start and enable the service named “httpd”
-
Write a Ansible Playbook to create a file called “index.html” in /var/www/html with some dummy html contents.
-
Write a Ansible Playbook to reboot a self machine.
-
Write a Ansible Playbook to install a package called “git”, “wget”.
-
Write a Ansible Playbook to clone git repo. thttps://github.com/scmgalaxy/ansible-role-template
-
Now Merge all Top Playbook into one and run and verify
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals
This is the complete playbook
—
– name: complete playbook
hosts: localhost
tasks:
– name: group deploy
ansible.builtin.group:
name: deploy
state: present
– name: create user
ansible.builtin.user:
name: deploy-user
state: present
groups: deploy
shell: “/bin/bash”
– name: install se httpd
ansible.builtin.apt:
name: apache2
state: latest
– name: Start service
ansible.builtin.service:
name: apache2
state: started
– name: copy file
ansible.builtin.copy:
content: “<h1> Hola Mundo </h1>”
dest: /var/www/html/index.html
– name: reboot machines
ansible.builtin.reboot:
reboot_timeout: 3600
– name: install packages
ansible.builtin.apt:
name: git,wget
state: latest
– name: replicate repository
ansible.builtin.git:
repo: https://github.com/scmgalaxy/ansible-role-template
dest: /home/ubuntu/ansible-role-template
– name: Linus lab
hosts: localhost
become: yes
tasks:
– name: Create a user group
group:
name: deploy
state: present
– name : Create user and add to deploygroup
user:
name: deploy-user
group: deploy
shell: /bin/bash
home: /home/deploy-user
– name: install httpd
yum:
name: httpd
state: installed
– name: Starting a Apache Server
ansible.builtin.service:
name: apache2
state: started
– name: Copy file with owner and permissions
ansible.builtin.copy:
src: index.html
dest: /var/www/html/index.html
– name: Install install git
ansible.builtin.apt:
name: “git”
state: present
– name: Install install git
ansible.builtin.apt:
name: “wget”
state: present
– name: Git checkout
ansible.builtin.git:
repo: ‘https://github.com/scmgalaxy/ansible-role-template’
dest: /tmp/checkout
1
– name: create group
hosts: all
tasks:
– name: create group “deployE
ansible.builtin.group:
name: deploy
state: present
2
– name: create user
hosts: all
tasks:
– name: create group “deployE
ansible.builtin.user:
name: deploy-user
state: present
shell: /bin/bash
3
– name: install package
hosts: all
tasks:
– name: install package httpd
ansible.builtin.apt:
name: httpd
state: present
4
– name: start service httpd
hosts: all
tasks:
– name: Start service httpd
ansible.builtin.service:
name: httpd
state: started
5
– name: create file
hosts: all
tasks:
– name: create file
ansible.builtin.file:
dest: /var/www/html/index.html
state: touch
6
– name: create file
hosts: all
tasks
– name: reboot the machine with all defaults
ansible.builtin.reboot:
7
– name: install package
hosts: all
vars:
packages:
– git
– wget
tasks:
– name: install package httpd
ansible.builtin.apt:
name: “{{ item }}
state: present
with_items: “{{packages}}”
1. Write a Ansible Playbook to create a group called “deploy”
—
– name: Create the “deploy” group
hosts: localhost
become: yes
tasks:
– name: Ensure the “deploy” group exists
group:
name: deploy
state: present
2. Write a Ansible Playbook to create a user called “deploy-user” which is part of group called “deploy” and with /bin/bash shell.
—
– name: Create the “deploy-user” and add to the “deploy” group
hosts: localhost
become: yes
tasks:
– name: Ensure the “deploy” group exists
group:
name: deploy
state: present
– name: Create the “deploy-user” user
user:
name: deploy-user
group: deploy
shell: /bin/bash
state: present
3. Write a Ansible Playbook to install package named “httpd” in RHEL/centos.
—
– name: Install httpd package
hosts: localhost
become: yes
tasks:
– name: Install the httpd package
package:
name: httpd
state: present
4. Write a Ansible Playbook to start and enable the service named “httpd”
—
– name: Start and enable the httpd service on RHEL
hosts: localhost
become: yes
tasks:
– name: Ensure the httpd service is enabled
service:
name: httpd
enabled: yes
– name: Start the httpd service
service:
name: httpd
state: started
5. Write a Ansible Playbook to create a file called “index.html” in /var/www/html with some dummy html contents.
—
– name: Create index.html in /var/www/html
hosts: localhost
become: yes
tasks:
– name: Create the directory if it doesn’t exist
file:
path: /var/www/html
state: directory
– name: Create the index.html file
copy:
content: |
<!DOCTYPE html>
<html>
<head>
<title>Dummy Page</title>
</head>
<body>
<h1>This is a dummy HTML page</h1>
</body>
</html>
dest: /var/www/html/index.html
6. Write a Ansible Playbook to reboot a self machine.
—
– name: Reboot the local machine
hosts: localhost
become: yes
tasks:
– name: Reboot the machine
reboot:
Write a Ansible Playbook to start and enable the service named “httpd”
—
– name: Start and Enable the httpd Service
hosts: rhel
become: yes
tasks:
– name: httpd install and start
service:
name: httpd
state: started
enabled: yes
Write a Ansible Playbook to reboot a self machine.
—
– name: Reboot Managed Node
hosts: centos
become: yes
tasks:
– name: Reboot the managed node
reboot:
Write a Ansible Playbook to install a package called “git”, “wget”.
—
– name: Install Git and Wget
hosts: centos
become: yes
tasks:
– name: Install Git and Wget
yum:
name:
– git
– wget
state: present
– name: Install Git and Wget on Debian-based systems
apt:
name:
– git
– wget
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: Create user
hosts: rhel
become: yes
tasks:
– name: Create group
group:
name: deploy
state: present
– name: Create user
user:
name: deploy-user
group: deploy
shell: /bin/bash
notify: Restart SSH
handlers:
– name: Restart SSH
service:
name: ssh
state: restarted
Write a Ansible Playbook to clone git repo. thttps://github.com/scmgalaxy/ansible-role-template
—
– name: Clone Repository
hosts: rhel
become: yes
tasks:
– name: Clone the GitHub repository
git:
repo: https://github.com/scmgalaxy/ansible-role-template.git
dest: /tmp/scmgalaxy
--- - name: Lab excercise hosts: localhost tasks: - name: make sure group exist group: name: deploy state: present - name: make sure user exist user: name: deploy-user group: deploy shell: /bin/bash - name: make sure latest apache is installed apt: name: apache2 state: latest - name: make sure apache is started service: name: apache2 state: started - name: make sure the index html is in place copy: src: index.html dest: /var/www/html/ - name: make sure second html is in place copy: content: 'second file content' dest: /var/www/html/second.html - name: apt: state: present name: - git - wget - name: Clone repo git: repo: https://github.com/scmgalaxy/ansible-role-template dest: /root/ansible-role-template clone: yes update: yes ...