Difference between revisions of "Ansible Roles"

From rbachwiki
Jump to navigation Jump to search
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Create Roles to organize playbooks=
= Create Roles to organize playbooks=
<code> /etc/ansible/roles </code>
'''Make a directory for each role'''
mkdir [rolenames]


===This Playbook has some tasks to be done==
mkdir basicinstall
mkdir fullinstall
 
'''Create sub-directory <code>tasks</code> within each directory'''
 
mkdir basicinstall/tasks
mkdir fullinstall/tasks
 
'''Create yml files within these sub-directory'''
basicinstall/tasks/main.yml
fullinstall/tasks/main.yml
 
===This Playbook has some tasks to be done===
  ---
  ---
  - name: Install httpd package
  - name: Install httpd package
Line 45: Line 60:
   - fullinstall
   - fullinstall
   
   
- name: Basic install
- name: Basic install
   hosts: localhosts
   hosts: localhosts
   roles:
   roles:
   - basicinstall
   - basicinstall
=[[Ansible| Ansible Menu]]=
[[Category:Ansible]]

Latest revision as of 20:09, 12 July 2022

Create Roles to organize playbooks

/etc/ansible/roles Make a directory for each role

mkdir [rolenames]
mkdir basicinstall
mkdir fullinstall

Create sub-directory tasks within each directory

mkdir basicinstall/tasks
mkdir fullinstall/tasks

Create yml files within these sub-directory

basicinstall/tasks/main.yml
fullinstall/tasks/main.yml

This Playbook has some tasks to be done

---
- name: Install httpd package
 yum:
  name: httpd
  state: present

- name: Start httpd
 service:
  name: httpd
  state: started

- name: Open port for http
 firewalld:
  service: http
  permanent: true
  state: enabled

- name: Restart firewalld 
 service:
  name: firewalld
  state: reloaded

Another Playbook with some more tasks

---
- name: Install httpd package
 yum:
  name: httpd
  state: present

 - name: Start httpd
   service:
    name: httpd
    state: started

Role that incorporate the other 2 playbooks

---
- name: Full install
 hosts: all
 roles:
 - fullinstall

- name: Basic install
 hosts: localhosts
 roles:
 - basicinstall


Ansible Menu