Ansible用变量安装httpd
下载httpd安装包
[root@localhost ansible]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.48.tar.gz
[root@localhost ansible]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.7.0.tar.gz
[root@localhost ansible]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
[root@localhost ansible]# ls
apr-util-1.6.1.tar.gz ansible.cfg inventory
apr-1.7.0.tar.gz group_vars httpd-2.4.48.tar.gz playbook
编写playbook
[root@localhost ansible]# cat install.yml
---
- hosts: 192.168.100.42
tasks:
- name: install base packges
yum:
name: '{{item}}'
state: present
with_items:
- pcre
- pcre-devel
- expat-devel
- gcc
- gcc-c++
- openssl-devel
- make
- name: uncompress apr
unarchive:
src: /etc/ansible/apr-1.7.0.tar.gz
dest: /opt/
- name: uncompress util
unarchive:
src: /etc/ansible/apr-util-1.6.1.tar.gz
dest: /opt/
- name: uncompress httpd
unarchive:
src: /etc/ansible/httpd-2.4.48.tar.gz
dest: /opt/
- name: configure
lineinfile:
path: /opt/apr-1.7.0/configure
regexp: '^$RM "$cfgfile"'
line: '# $RM "$cfgfile"'
- name: install apr
shell: cd /opt/apr-1.7.0 && ./configure --prefix=/usr/local/apr && make && make install
- name: install apr-util
shell: 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/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ && make && make install
[root@localhost ansible]#
执行
[root@localhost ansible]# ansible-playbook install.yml
PLAY [192.168.100.42] ***************************************************************************************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************************************************************************************
ok: [192.168.100.42]
TASK [install base packges] *********************************************************************************************************************************************************************
[DEPRECATION WARNING]: Invoking "yum" only once while using a loop via squash_actions is deprecated. Instead of using a loop to supply multiple items and specifying `name: "{{item}}"`, please
use `name: ['pcre', 'pcre-devel', 'expat-devel', 'gcc', 'gcc-c++', 'openssl-devel', 'make']` and remove the loop. This feature will be removed in version 2.11. Deprecation warnings can be
disabled by setting deprecation_warnings=False in ansible.cfg.
ok: [192.168.100.42] => (item=['pcre', 'pcre-devel', 'expat-devel', 'gcc', 'gcc-c++', 'openssl-devel', 'make'])
TASK [uncompress apr] ***************************************************************************************************************************************************************************
changed: [192.168.100.42]
TASK [uncompress util] **************************************************************************************************************************************************************************
ok: [192.168.100.42]
TASK [uncompress httpd] *************************************************************************************************************************************************************************
ok: [192.168.100.42]
TASK [configure] ********************************************************************************************************************************************************************************
changed: [192.168.100.42]
TASK [install apr] ******************************************************************************************************************************************************************************
changed: [192.168.100.42]
TASK [install apr-util] *************************************************************************************************************************************************************************
changed: [192.168.100.42]
TASK [install httpd] ****************************************************************************************************************************************************************************
changed: [192.168.100.42]
PLAY RECAP **************************************************************************************************************************************************************************************
192.168.100.42 : ok=9 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[root@localhost ansible]#
关闭防火墙
[root@localhost ansible]# ansible all -m service -a 'name=firewalld state=stopped enabled=no'
192.168.100.42 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"enabled": false,
"name": "firewalld",
"state": "stopped",
"status": {
"ActiveState": "active",
"AllowedCPUs": "",
"AllowedMemoryNodes": "",
"BlockIOAccounting": "no",
。。。。。。
关闭selinux
[root@localhost ansible]# ansible all -m lineinfile -a 'path=/etc/selinux/config regexp="^SELINUX=" line="SELINUX=disabled"'
192.168.100.42 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line replaced"
}
[root@localhost ansible]#
重启httpd
[root@localhost ansible]# ansible all -a '/usr/local/httpd/bin/apachectl start'
192.168.100.42 | CHANGED | rc=0 >>
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[root@localhost ansible]#
访问ip进行测试