Ansible Playbook Lab & Excercise – Part 2

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now
---
- 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"

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"