Ansible: a Configuration Management tool

apache.yml

---

- hosts: web
  tasks:
  - name: deploy apache
    yum: pkg-httpd state=latest
  - name: apache config file
    copy: src='files/httpd.conf' dest='/etc/httpd/conf/httpd.conf'
    notify:
    - restart httpd
  - name: apache service runs
    service: name-httpd state=started
  handlers:
    - name: restart httpd
      service: name=httpd state=restarted


Adding NTP deployment tasks to /etc/ansible/roles/web/tasks.main.yml

---

  - include_vars: "{{ ansible_os_family }}.yml"
  - name: Deploy Apache for Red Hat systems
    yum: pkg-httpd state=latest
    when: ansible_os_family' == 'RedHat'
  - name: Deploy Apache for Debian systems
    apt: pkg=apache2 state=latest
    when: ansible_os_family == 'Debian'
  - name: Apache Config File
    copy: src={{ conffile }} dest={{ confpath }}
    notify:
    - config file update
  - name: Apache Service Runs
    service: name={{ webserver }} state=started
  - name: Deploy NTP on Ubuntu servers
    apt: pkg=ntp state=latest
    when: ansible_os_family == 'Debian'
  - name: Deploy NTP for Red Hat systems
    yum: pkg=ntp state=latest
    when: ansible_os_family == 'RedHat'
  - name: NTP Service Runs
    service: name={{ ntpserver }} state=started










No comments:

Post a Comment