• LOGIN
  • No products in the cart.

DevOps on AWS – Ansible PlayBook Exercises – 1

Playbook – 1:

— # Basic Yaml (basic.yml)
– hosts: centos
  remote_user: ansible
  become: yes
  become_method: sudo
  tasks:
  – name: Querying for Telnet Install
    yum: pkg=telnet state=present update_cache=true

Playbook – 2:

— # Installing Httpd Server and Starting it (structure.yml)
–   hosts: centos
    remote_user: ansible
    become: yes
    become_method: sudo
    connection: ssh
    gather_facts: yes
    tasks:
    – name: Install httpd server on centos
      yum:
        name: httpd
        state: latest
      notify:
       – startservice
    handlers:
    – name: startservice
      service:
         name: httpd
         state: restarted

Playbook – 3:

— # Playbook with Variable Substitution (VarSubStitution.yml)
–   hosts: ‘{{ myHosts }}’
    remote_user: ‘{{ sudoUser }}’
    become: ‘{{ becomeSudoUser }}’
    become_method: sudo
    connection: ssh
    gather_facts: ‘{{ gather }}’
    vars:
        myHosts: centos
        gather: yes
        pkg: telnet  
        sudoUser: ansible    
        becomeSudoUser: yes        
    tasks:
    – name: Install telnet server on centos
      yum:
        name: ‘{{ pkg }}’
        state: latest    


Playbook – 4:

— # Conditional Based PlayBook (conditional.yml)
–  hosts: centos
   remote_user: ansible
   become: yes
   become_method: sudo
   connection: ssh
   gather_facts: yes
   tasks: 
   – name: If Os is RedHat install Http
     yum:
         name: httpd
         state: present
     when: ansible_os_family == ‘RedHat’


Playbook – 5:

— # Create File and Add the line to the File
–  hosts: centos
   tasks: 
   – name: create a file if does not exist
     file:
         state: touch
         path: /home/ansible/hostname.conf
   – name: If line not there then add it
     lineinfile:
            state: present
            dest: /home/ansible/hostname.conf
            line: Hostname={{ ansible_hostname}}

Playbook – 6:

— # Playbook for Debugging
–   hosts: ‘{{ myHosts }}’
    remote_user: ansible
    become: yes
    become_method: sudo
    connection: ssh
    gather_facts: ‘{{ gather }}’
    vars:
        myHosts: centos
        gather: yes
        pkg: telnet
    tasks:
    – name: Install telnet server on centos
      yum:
        name: ‘{{ pkg }}’
        state: latest
      register: result
    – debug: var=result
February 22, 2021

0 responses on "DevOps on AWS - Ansible PlayBook Exercises - 1"

    All rights reserved.
    error: Alert: Content is protected !!
    X