Day 3 – Ansible Notes – Pep – Aug – 2023

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
Variables - DONE
Files - DONE

Looping - 
https://www.devopsschool.com/blog/working-with-ansible-loop-and-iterators-with-example/
https://www.devopsschool.com/tutorial/ansible/ansible-looping-programming-playbooks.html

Template - 
================================================
---
- name: Install and configure web server
  hosts: web
  vars:
    myname: raju

  tasks:
    - name: Copy file with owner and permissions
      ansible.builtin.copy:
        src: index.html
        dest: /var/www/html/index.html
    - name: Copy file with owner and permissions
      ansible.builtin.copy:
        src: index.html
        dest: /var/www/html/{{ myname }}.html

----------------------------------------------------
{{ myname }} in the file used in playbook - index.html

vi index.html

{{ myname }}
===================================================================
Conclusion
	- vars used in playbook - Would Interop*
	- Vars used in the filed used in playbook - NOT

Template
----------------------------------------
	Powered by  Jinja2

How to do it?
Cond1 - You need to make a file used in a playbook with .j2 ext. == index.html --> index.html.j2
Cond2 - Use Template module




---
- name: Install and configure web server
  hosts: localhost
  vars:
    myname: raju
    apacheport: 81

  tasks:
    - name: Template a file to /etc/file.conf
      ansible.builtin.template:
        src: index.html.j2
        dest: /var/www/html/index.html
    - name: Start service httpd, if not started
      ansible.builtin.service:
        name: httpd
        state: stopped
    - name: Template a file to httpd.conf.j2
      ansible.builtin.template:
        src: httpd.conf.j2
        dest: /etc/httpd/conf/httpd.conf
    - name: Start service httpd, if not started
      ansible.builtin.service:
        name: httpd
        state: started
    - name: Copy file with owner and permissions
      ansible.builtin.copy:
        src: index.html
        dest: /var/www/html/{{ myname }}.html



Handlers - Pending

Variables - DONE
Files - DONE

Looping - 
https://www.devopsschool.com/blog/working-with-ansible-loop-and-iterators-with-example/
https://www.devopsschool.com/tutorial/ansible/ansible-looping-programming-playbooks.html

Template - 
================================================
---
- name: Install and configure web server
  hosts: web
  vars:
    myname: raju

  tasks:
    - name: Copy file with owner and permissions
      ansible.builtin.copy:
        src: index.html
        dest: /var/www/html/index.html
    - name: Copy file with owner and permissions
      ansible.builtin.copy:
        src: index.html
        dest: /var/www/html/{{ myname }}.html

----------------------------------------------------
{{ myname }} in the file used in playbook - index.html

vi index.html

{{ myname }}
===================================================================
Conclusion
	- vars used in playbook - Would Interop*
	- Vars used in the filed used in playbook - NOT

Template
----------------------------------------
	Powered by  Jinja2

How to do it?
Cond1 - You need to make a file used in a playbook with .j2 ext. == index.html --> index.html.j2
Cond2 - Use Template module




---
- name: Install and configure web server
  hosts: localhost
  vars:
    myname: raju
    apacheport: 80

  tasks:
    - name: Template a file to /etc/file.conf
      ansible.builtin.template:
        src: index.html.j2
        dest: /var/www/html/index.html
    - name: Template a file to httpd.conf.j2
      ansible.builtin.template:
        src: httpd.conf.j2
        dest: /etc/httpd/conf/httpd.conf
      notify:
        - Restart HTTPD services
        - Restart HTTPD servicesesdfsdr
    - name: Start service httpd, if not started
      ansible.builtin.service:
        name: httpd
        state: started
    - name: Copy file with owner and permissions
      ansible.builtin.copy:
        src: index.html
        dest: /var/www/html/{{ myname }}.html

  handlers:
    - name: Restart HTTPD services
      ansible.builtin.service:
        name: httpd
        state: restarted
    - name: Restart HTTPD servicsdasdaesads
      ansible.builtin.service:
        name: httpd
        state: restarted
	




==========================
Handlers - Pending
=======================


====================================================================
ROLES
====================================================================
-------- How you manage Code?
			Variable(S)?
			Task(S)
			File(S)
			Template(S)
			Handler(s)
--------------------------------------------
ROLE
	 a dir structure to manage
			Variable(S)?
			Task(S)
			File(S)
			Template(S)
			Handler(s)
================================================
	Custom ROLE		| 		Use Community Role
=====================================================================
					ansible-galaxy
	


---
- name: Install and configure web server
  hosts: localhost

  roles:
    - roles/web
    - geerlingguy.java




 290  ansible-galaxy install geerlingguy.java
  291  ansible-galaxy
  292  ansible-galaxy role
  293  ansible-galaxy role -h
  294  ansible-galaxy role list
  304  ansible-galaxy role init
  305  ansible-galaxy role -h
  306  ansible-galaxy init
  307  ansible-galaxy init web
  331  ansible-galaxy role list
  333  ansible-galaxy role list




https://github.com/devopsschool-demo-labs-projects/ansible-hello-world-role





Subscribe
Notify of
guest

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

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x