Ansible Playbook Lab & Excercise – Part 2

DevOps

MOTOSHARE 🚗🏍️
Turning Idle Vehicles into Shared Rides & Earnings

From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.

With Motoshare, every parked vehicle finds a purpose. Owners earn. Renters ride.
🚀 Everyone wins.

Start Your Journey with Motoshare
---
- name: To create group deploy
  hosts: web

  tasks:
  - name: to create group deploy
    group:
      name: deploy
      state: present

---
- name: To create group deploy which is part of deploy
  hosts: web

  tasks:
  - name: to create group deploy which is part of deploy
    user:
      name: deploy-user
      group: deploy
      state: present
 ---
- name: to install package
  hosts: web

  tasks:
  - name: to install package
    yum:
      name: httpd
      state: present

---
- name: to start and enable the service
  hosts: web

  tasks:
  - name: to start and enable the service
    service:
      name: httpd
     
---
- name: create a file
  hosts: web

  tasks:
  - name: create a file
   file:
    path: /var/www/html
    state: file

---
- name:  to reboot a self machine
  hosts: web

  tasks:
  - name:  to reboot a self machine
   reboot:
    reboot_timeout: 3600
   
---
- name: to install a package
  hosts: web

  tasks:
  - name: to install a package
   yum:
      name: git
      state: present

---
- name: to clone git repo
  hosts: web

  tasks:
  - name: to clone git repo
   git:
      dest: /home/centos/bhavya
      repo: "https://github.com/scmgalaxy/ansible-role-template"Code language: PHP (php)

9.Now Merge all Top Playbook into one and run and verify

playAllCmd.yaml
---
- name: merge all  commands
  hosts: web

  tasks:
  - name: to create group deploy
    group:
      name: deploy
      state: present
   - name: to create group deploy which is part of deploy
    user:
      name: deploy-user
      group: deploy
      state: present
  - name: Start service httpd, if not started
    ansible.builtin.service:
      name: httpd
      state: started
  - name: to install package
    yum:
      name: httpd
      state: present
  - name: to start and enable the service
     service:
       name: httpd
  - name: create a file
     file:
       path: /var/www/html
       state: file
   - name:  to reboot a self machine
     reboot:
       reboot_timeout: 3600
   - name: to install a package
     yum:
       name: git
       state: present
   - name: to clone git repo
      git:
       dest: /home/centos/ clone=yes
       repo: "https://github.com/scmgalaxy/ansible-role-template"Code language: PHP (php)