---标签:httpd,ver,name,apr,--,playbook,apache,安装,dir From: https://blog.51cto.com/dayu/5751655
- name: install httpd
hosts: all
vars:
dir: /usr/local/src
install_dir: /apps/httpd
httpd_ver: httpd-2.4.54
httpd_url: https://mirrors.tuna.tsinghua.edu.cn/apache/httpd
apr_url: https://mirrors.tuna.tsinghua.edu.cn/apache/apr
apr_ver: apr-1.7.0
apr_util_ver: apr-util-1.6.1
tasks:
- name: yum install packages
yum:
name: "{{item}}"
state: present
loop: [ gcc,make,pcre-devel,openssl-devel,expat-devel,bzip2 ]
when: ansible_distribution == "CentOS" or ansible_distribution == "Rocky"
- name: apt install packages
apt:
name: "{{item}}"
state: present
loop: [ gcc,make,libpcre3-dev,openssl,libssl-dev,expat,libexpat1-dev,bzip2 ]
when: ansible_distribution == "Ubuntu"
- name: download httpd
unarchive:
src: "{{ httpd_url }}/{{ httpd_ver }}.tar.gz"
dest: "{{ dir }}"
owner: root
remote_src: yes
- name: download apr
unarchive:
src: "{{ apr_url }}/{{ apr_ver }}.tar.gz"
dest: "{{ dir }}"
owner: root
remote_src: yes
- name: download apr-util
unarchive:
src: "{{ apr_url }}/{{ apr_util_ver }}.tar.gz"
dest: "{{ dir }}"
owner: root
remote_src: yes
- name: prepare apr
shell: chdir={{ dir }} mv {{ apr_ver }} {{ dir }}/{{ httpd_ver }}/srclib/apr
- name: prepare apr-util
shell: chdir={{ dir }} mv {{ apr_util_ver }} {{ dir }}/{{ httpd_ver }}/srclib/apr-util
- name: build
shell: chdir={{ dir }}/{{ httpd_ver }} ./configure --prefix={{ install_dir }} --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork && make && make install
- name: create group
group:
name: apache
gid: 80
system: yes
state: present
- name: create user
user:
name: apache
uid: 80
group: apache
system: yes
create_home: no
home: "{{ dir }}/conf/httpd"
- name: set httpd user
lineinfile:
path: "{{ install_dir }}/conf/httpd.conf"
regexp: '^User'
line: 'User apache'
- name: set httpd group
lineinfile:
path: "{{ install_dir }}/conf/httpd.conf"
regexp: '^Group'
line: 'Group apache'
- name: set servername
lineinfile:
path: "{{ install_dir }}/conf/httpd.conf"
regexp: '^#ServerName *'
line: 'ServerName localhost:80'
- name: set PATH
shell: echo PATH={{ install_dir }}/bin:$PATH >> /etc/profile.d/httpd.sh
- name: service
template:
src: httpd.service.j2
dest: /usr/lib/systemd/system/httpd.service
- name: reload service
systemd:
daemon_reload: yes
- name: start service
systemd:
name: httpd.service
state: started
enabled: yes