DevOps Classroomnotes 31/Dec/2022

Ansible Contd

YAML

  • It is a Data Description Format.
  • It is widely used to store
    • Data
    • Configurations
  • Data can be categorized into 2 types
    • Simple/Scalar:
      • Text name: Ansible
      • Number version: 2.13
      • Boolean opensource: yes
    • Complex
      • list/array (plural)
        “`yaml
        colors:</li>
        <li>red</li>
        <li>blue</li>
        <li>green
        “`
      • object/map/dictionary
        yaml
        address:
        flatno: 407
        building: mythrivanam
        city: Hyderabad
  • JSON/YAML use Key-Value (Name Value) pairs.
  • YAML Basic key value syntax is key: value
  • Sample YAML (Quality Thought)
---
name: QualityThought
contact:
  email: 
    - support@qualitythought.in
    - qualitythought.in@gmail.com
  phone:
    - 999999999
    - 888888888
address:
  - flat: 407
    building: mythrivanam
    city: Hyderabad
  - flat: 302
    building: Nilgiri
    city: Hyderabad

  • Good books to read
---
Purpose: Good Books to Read
Books:
  - Title: Your Brain at Work
    Author: David Rock
    ISBN: 978-0062312822
    Language: English
  - Title: Rich Dad Poor Dad
    Author: Robert Kiyosaki
    ISBN: 978-1612680194
    Language: English
  - Title: Who moved my cheese
    Author: Spencer Johnson
    ISBN: 978-0091883768
    Language: English
  • Write a yaml describing your favorite movies/holiday destinations
---
movies:
  - name:
    starcast:
      - 
      -
    technical:
      director:
      producer:
    release: 
  - 
  -

destinations:
  - name:
    modeoftransport: 
    spots:
      -
      -
      -

  • YAML files are generally stored with extensions .yaml or .yml

Ansible Playbook

  • Refer Here for official docs
  • The structure of the YAML is defined by Ansible
---
- name: <purpose>
  hosts: <where to execute>
  become: yes # whether to run the tasks with sudo
  tasks:
    - name: <task description> # individual step
      <module-name>:
         <param-1>: <value-1>
         ..
         <param-n>: <value-n>
    - name: <task description>
      <module-name>:
         <param-1>: <value-1>
         ..
         <param-n>: <value-n>
         state: <desired-state>

Lets write a playbook for Apache installation

  • Manual steps
sudo apt update
sudo apt install apache2 -y
  • Google apt in ansible Refer Here for the module page
  • Go through parameters and fill in the necessary parameters
  • Playbook: Refer Here for the changes done
  • Executing ansible playbook: Refer Here

  • Now re-execute the same command and ansible will not install apache2 but since apache2 exists it doesn’t change any thing
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Customized Social Media Icons from Acurax Digital Marketing Agency

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%