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
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 1
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 2
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 3
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 4
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 5
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 6
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 7
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 8
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 9
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 10
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 11
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 12
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 13
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 14
Beginner to Advanced Complete Ansible Tutorial in 15 hours 6-2021 Part – 15
Latest posts by Rajesh Kumar (see all)
- Top 10 Website Development Companies in Ludhiana - December 5, 2024
- Exploring Career Options: Why Trade Schools Are a Great Alternative - December 5, 2024
- Announcing the Launch of DevOpsSchool.jp Services in Japan: Transforming IT Operations in Tokyo and Beyond - December 3, 2024
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