C/C++教程

ansible playbook使用变量源码安装apache

本文主要是介绍ansible playbook使用变量源码安装apache,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

先在ansible主机上下载安装apache需要的文件

[root@ansible playbook]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.7.0.tar.gz
[root@ansible playbook]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
[root@ansible playbook]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.48.tar.gz

然后解压到本机上

[root@ansible playbook]# ls
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.48.tar.gz
[root@ansible playbook]# mkdir files
[root@ansible playbook]# tar -xf apr-1.7.0.tar.gz -C files/
[root@ansible playbook]# tar -xf apr-util-1.6.1.tar.gz -C files/
[root@ansible playbook]# tar -xf httpd-2.4.48.tar.gz -C files/
[root@ansible playbook]# ls files/
apr-1.7.0  apr-util-1.6.1  httpd-2.4.48
[root@ansible playbook]#

然后写playbook文件

[root@ansible project]# cat playbook/apache.yml 
---
- name: install apache
  hosts: all
  vars:
    apr_name: apr-1.7.0 
    apr_util_name: apr-util-1.6.1
    httpd_name: httpd-2.4.48
  tasks:
    - name: copy apr
      copy:
        src: files/{{apr_name}}
        dest: /root/

    - name: copy apr-util
      copy:
        src: files/{{apr_util_name}}
        dest: /root/

    - name: copy httpd
      copy:
        src: files/{{httpd_name}}
        dest: /root/

    - name: stop firewalld 
      service:
        name: firewalld
        state: stopped
        enabled: no

    - name: stop selinux
      lineinfile:
        path: /etc/selinux/config
        regexp: "^SELINUX="
        line: "SELINUX=disabled"
        state: present

    - name: install utils
      yum:
        name: "{{item}}"
        state: present
      with_items:
        - openssl-devel
        - pcre-devel
        - pcre
        - perl
        - perl-devel
        - expat-devel
        - libtool
        - gcc
        - make
        - gcc-c++

    - name: edit config
      lineinfile:
        path: /root/{{apr_name}}/configure
        regexp: '^    $RM "$cfgfile"'
        line: '#    $RM "$cfgfile"'

    - name: install apr
      shell: |
        cd /root/apr-1.7.0
        ./configure --prefix=/usr/local/apr
        make && make install

    - name: install apr-util
      shell: |
        cd /root/apr-util-1.6.1
        ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
        make && make install

    - name: install httpd
      shell: |
        cd /root/httpd-2.4.48
        ./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
        make && make install
    
    - name: edit httpd config
      lineinfile:
        path: /usr/local/httpd/conf/httpd.conf
        regexp: "^#ServerName www.example.com:80"
        line: "ServerName www.example.com:80"

    - name: start httpd
      shell: '/usr/local/httpd/bin/apachectl start'
[root@ansible project]#

查看测试结果

这篇关于ansible playbook使用变量源码安装apache的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!