Install Apache on a RHEL/CentOS server
---
- hosts: all
sudo: yes
tasks:
- name: Install Apache
yum:name={{ item }} state=present
with_items:
- httpd
- httpd-devel
- name: Copy configuration files
copy:
src: "{{ item.src }}
dest: "{{ item.dest }}"
owner: root
group: root
mode: 0644
with_items:
- src: "httpd.conf"
dest: "/etc/httpd/conf/httpd.conf"
- src: "httpd-vhosts.conf"
dest: "/etc/httpd/conf/httpd-vhosts.conf"
- name: Make sure Apache is started and now and at boot
service: name=httpd state=started enabled=yes
Install Apache on different flavors of Linux using blocks
---
- hosts: web
tasks:
# Install and configure Apache on RedHat/CentOS hosts
- block:
- yum: name=httpd state=present
- template: src=httpd.conf.j2 dest=/etc/httpd/conf/httpd.conf
- service: name=httpd state=started enabled=yes
when: ansible_os_family == 'RedHat'
sudo: yes
# Install and configure Apache on Debian/Ubuntu hosts
- block:
- apt: name=apache2 state=present
- template: src=httpd.conf.j2 dest=/etc/apache2/apache2.conf
- service: name=apache2 state=started enabled=yes
when: ansible_os_family == 'Debian'
sudo: yes
No comments:
Post a Comment