Selfnote of ANSIBLE PLAYBOOK –

  • Write a Ansible Playbook to create a group called “deploy” :
$ ansible Create a group name=deploy state=present

- name: Deploy
  hosts: webservers

  tasks:
  - name: create a group
    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 :
$ ansible name=deploy-user group=deploy shell=/bin/bash state=present

- name: Deploy
  hosts: webservers

  tasks:
  - name: create user
    user:
      name: deploy-user

      shell:/bin/bash
      group: deploy
  • Write a Ansible Playbook to install package named “httpd” in RHEL/centos :
$ install Apache name=httpd

- name: Start Installing Package
  hosts: webservers

  tasks:
  - name: install package
    yum:
      name: httpd

      state: present
  • Write a Ansible Playbook to start and enable the service named “httpd” :
$ ansible localhost -m service -a"name=httpd state=started"

- name: Starting the service
  hosts: webservers

  tasks:
  - name: start service
    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 :
$ ansible Create a file dest=/var/www/html/index.html mode=600 state=touch

- name: Initiating File Creation
  hosts: webservers

  tasks:
  - name: creating a file
    copy:
      src: index.html

      dest: /var/www/html/index.html
  • Write a Ansible Playbook to reboot a self machine :
$ ansible all -m ansible.builtin.reboot -a"name=reboot the machine"


- name: Started reboot
  hosts: webservers

  tasks:
  - name: rebooting the machine
    reboot:
      name: reboot the machine
      msg: rebooting the machine
  • Write a Ansible Playbook to install a package called “git”, “wget” :
$ ansible Install git, wget packages name=git,wget state=present