当前位置: 代码迷 >> 综合 >> ansible playbook编译安装apache
  详细解决方案

ansible playbook编译安装apache

热度:101   发布时间:2023-12-04 04:41:47.0

ansible playbook编译安装apache

结构

[root@master apache]# tree
.
├── 1
├── 1.pub
├── ansible.cfg
├── group_vars
│   └── apache
├── install.yml
├── inventory
├── packages
│   ├── apr-1.7.0.tar.gz
│   ├── apr-util-1.6.1.tar.gz
│   └── httpd-2.4.48.tar.gz
└── vars└── httpd.yml

下载httpd及依赖包的压缩包

httpd安装包地址: https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/
.
apr安装包地址: https://mirrors.tuna.tsinghua.edu.cn/apache/apr/
.

编辑httpd.yml

[root@master vars]# cat httpd.yml 
packages: - openssl-devel- pcre-devel- expat-devel- libtool- gcc- gcc-c++- make- pcre- perl-devel- perl- '@ Development Tools'user: apache

编辑install.yml

[root@master apache]# cat install.yml 
---
- hosts: apachevars_files:- vars/httpd.ymltasks:- name: create nameuser:name: '{
   {user}}'system: yescreate_home: noshell: /sbin/nologinstate: present- name: install base packagesyum:  name: '{
   {item}}'state: presentloop: '{
   {packages}}'- name: uncompress aprunarchive:src: packages/apr-1.7.0.tar.gzdest: /opt/- name: uncompress apr-utilunarchive:src: packages/apr-util-1.6.1.tar.gzdest: /opt/- name: uncompress httpdunarchive:src: packages/httpd-2.4.48.tar.gzdest: /opt/- name: configurelineinfile:path: /opt/apr-1.7.0/configureregexp: '^$RM "$cfgfile"'line: '# $RM "$cfgfile"'- name: install aprshell: cd /opt/apr-1.7.0 && ./configure  --prefix=/usr/local/apr && make && make install- name: install apr-utilshell: cd /opt/apr-util-1.6.1 && ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install- name: install httpd shell: cd /opt/httpd-2.4.48 && ./configure --prefix=/usr/local/apache  --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/  && make && make install

执行

[root@master apache]# ansible-playbook install.yml PLAY [apache] **************************************************************************************************************************TASK [Gathering Facts] *****************************************************************************************************************
ok: [192.168.72.137]TASK [create name] *********************************************************************************************************************
ok: [192.168.72.137]TASK [install base packages] ***********************************************************************************************************
ok: [192.168.72.137] => (item=openssl-devel)
ok: [192.168.72.137] => (item=pcre-devel)
ok: [192.168.72.137] => (item=expat-devel)
ok: [192.168.72.137] => (item=libtool)
ok: [192.168.72.137] => (item=gcc)
ok: [192.168.72.137] => (item=gcc-c++)
ok: [192.168.72.137] => (item=make)
ok: [192.168.72.137] => (item=pcre)
ok: [192.168.72.137] => (item=perl-devel)
ok: [192.168.72.137] => (item=perl)
ok: [192.168.72.137] => (item=@ Development Tools)TASK [uncompress apr] ******************************************************************************************************************
changed: [192.168.72.137]TASK [uncompress apr-util] *************************************************************************************************************
changed: [192.168.72.137]TASK [uncompress httpd] ****************************************************************************************************************
changed: [192.168.72.137]TASK [configure] ***********************************************************************************************************************
changed: [192.168.72.137]TASK [install apr] *********************************************************************************************************************
changed: [192.168.72.137]TASK [install apr-util] ****************************************************************************************************************
changed: [192.168.72.137]TASK [install httpd] *******************************************************************************************************************
changed: [192.168.72.137]PLAY RECAP *****************************************************************************************************************************
192.168.72.137             : ok=10   changed=7    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

访问

在这里插入图片描述

  相关解决方案