Wednesday, November 27, 2019

Include example

install_apache.yaml
This is just set of tasks.Not a complete playbook as no declarations of hosts or tasks keywords.


---

- name: install on debian
  apt: name=apache2 state=latest update_cache=yes
  when: ansible_os_family == "Debian"

- name: install on centos
  apt: name=httpd state=latest update_cache=yes
  when: ansible_os_family == "RedHat"

- name: start debian service
  service: name=apache2 enabled=yes state=started
  when: ansible_os_family == "Debian"

- name: start centos service
  service: name=httpd enabled=yes state=started
  when: ansible_os_family == "RedHat"

update_systems.yaml
This is a complete playbook as we can see hosts and tasks declaration.


---

  - hosts: all
    become: yes

    tasks:
      - name: update apt
        apt: upgrade=dist update_cache=yes
        when: ansible_os_family == "Debian"
    
      - name: update yum
        yum: upgrade=dist update_cache=yes
        when: ansible_os_family == "RedHat"

main playbook where above playbook and tasks file is included.


---
- include: Desktop/update_systems.yaml

- hosts: gui
  become: yes
  tasks:
   - include: Desktop/install_apache.yaml

No comments:

Post a Comment