ansible概述、ansible基礎 、 ad-hoc、批量配置管理
1 案例1:環境準備
1.1 問題
本案例要求準備ansible的基礎環境:
- 啟動6臺虛擬機器
- 禁用selinux和firewalld
- 編輯/etc/hosts
- 配置yum擴充套件源並在管理節點安裝ansible
1.2 方案
此方案需要準備六臺主機,1臺管理主機,5臺託管主機,以實現批量程式部署,批量執行命令等功能,具體要求如表-1所示:
表-1
1.3 步驟
實現此案例需要按照如下步驟進行。
步驟一:基礎環境準備
1)啟動6臺虛擬機器,由於已經講過怎麼建立,這裡不再在案例裡體現
2)真機配置yum倉庫
- [[email protected] ~]# tar -xf ansible_soft.tar.xz
- [[email protected] ~]# cd ansible_soft/
- [[email protected] ansible_soft]# mkdir /var/ftp/ansible
- [[email protected] ansible_soft]# cp * /var/ftp/ansible
- [[email protected] ansible_soft]# createrepo /var/ftp/ansible
- Spawning worker 0 with 1 pkgs
- Spawning worker 1 with 1 pkgs
- Spawning worker 2 with 1 pkgs
- Spawning worker 3 with 1 pkgs
- Spawning worker 4 with 1 pkgs
- Spawning worker 5 with 1 pkgs
- Workers Finished
- Saving Primary metadata
- Saving file lists metadata
- Saving other metadata
- Generating sqlite DBs
- Sqlite DBs complete
3)修改主機名(容易區分,6臺機器都需要修改)這裡以ansible主機為例子
- [[email protected] ~]# echo ansible > /etc/hostname
- [[email protected] ~]# hostname ansible
4)配置ip(6臺機器都需要配置),這裡以ansible主機為例子
- [[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
- # Generated by dracut initrd
- DEVICE="eth0"
- ONBOOT="yes"
- IPV6INIT="no"
- IPV4_FAILURE_FATAL="no"
- NM_CONTROLLED="no"
- TYPE="Ethernet"
- BOOTPROTO="static"
- IPADDR=192.168.1.51
- PREFIX=24
- GATEWAY=192.168.1.254
- [[email protected] ~]# systemctl restart network
- [[email protected] ~]# ifconfig
- eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- inet 192.168.1.51 netmask 255.255.255.0 broadcast 192.168.1.255
- ether 52:54:00:b2:69:9e txqueuelen 1000 (Ethernet)
- RX packets 234 bytes 16379 (15.9 KiB)
- RX errors 0 dropped 36 overruns 0 frame 0
- TX packets 31 bytes 2618 (2.5 KiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
5)配置yum客戶端,在管理節點ansible上面配置
- [[email protected] ~]# vim /etc/yum.repos.d/local.repo
- [local_repo]
- name=CentOS-$releasever - Base
- baseurl="ftp://192.168.1.254/system"
- enabled=1
- gpgcheck=1
- [local]
- name=local
- baseurl="ftp://192.168.1.254/ansible"
- enabled=1
- gpgcheck=0
- [[email protected] ~]# yum clean all
- [[email protected] ~]# yum repolist
- [[email protected] ~]# yum -y install ansible
- [[email protected] ~]# ansible --version
- ansible 2.4.2.0 //顯示版本說明安裝成功
- config file = /etc/ansible/ansible.cfg
- configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
- ansible python module location = /usr/lib/python2.7/site-packages/ansible
- executable location = /usr/bin/ansible
- python version = 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
6)請在6臺主機上面配置/etc/hosts,這裡以ansible主機為例子
- [[email protected] ansible]# cat /etc/hosts
- 192.168.1.51 ansible
- 192.168.1.52 web1
- 192.168.1.53 web2
- 192.168.1.54 db1
- 192.168.1.55 db2
- 192.168.1.56 cache
2 案例2:主機定義與分組:
2.1 問題
本案例要求:
- 熟悉ansible配置檔案
- 定義主機,分組和子組練習
- 自定義檔案,多配置路徑練習
2.2 步驟
實現此案例需要按照如下步驟進行。
步驟一:ansible.cfg配置檔案
- [[email protected] ~]# cd /etc/ansible/
- [[email protected] ansible]# ls
- ansible.cfg hosts roles
- [[email protected] ansible]# vim ansible.cfg
- #inventory = /etc/ansible/hosts //指定分組檔案路徑,主機的分組檔案hosts
- [selinux] //組名稱,selinux的相關選項在這個下面配置
- ...
- [colors] //組名稱,colors的相關選項在這個下面配置
- ...
步驟二:定義主機,分組和子組練習
1)靜態主機的定義
- [[email protected] ansible]# vim hosts
- [web]
- web1
- web2
- [db]
- db[1:2] //1:2為db1到db2兩臺主機,1:20為db1到db20多臺主機
- [other]
- cache
- [[email protected] ansible]# ansible web --list-host //顯示web組的主機
- hosts (2):
- web1
- web2
- [[email protected] ansible]# ansible db --list-host
- hosts (2):
- db1
- db2
- [[email protected] ansible]# ansible other --list-host
- hosts (1):
- cache
- [[email protected] ansible]# ansible all --list-host //顯示所有組的主機
- hosts (5):
- web1
- web2
- cache
- db1
- db2
2)直接測試
- [[email protected] ansible]# ansible cache -m ping
- //測試是否可以連線,若失敗顏色為紅色
- cache | UNREACHABLE! => {
- "changed": false,
- "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname cache: Name or service not known\r\n",
- "unreachable": true
- }
3)修改後測試
- [[email protected] ansible]# vi hosts
- [other]
- cache ansible_ssh_user="root" ansible_ssh_pass="a"
- [[email protected] ansible]# ansible other -m ping //測試成功,顏色為綠色
- cache | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
4)不檢測主機的sshkey,在第一次連線的時候不用輸入yes
- [[email protected] ansible]# vim ansible.cfg
- 61 host_key_checking = False
- [[email protected] ansible]# vim hosts
- [web]
- web1
- web2
- [web:vars] //web組:變數(vars不改),web組的多臺機器共用一個使用者名稱和密碼
- ansible_ssh_user="root"
- ansible_ssh_pass="a"
- [[email protected] ansible]# ansible web -m ping
- web2 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- web1 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
步驟三:定義子組
- [[email protected] ansible]# vi hosts
- [app:children] //指定子分組(app可改:children不改),web,db是提前分好的組
- web
- db
- [app:vars]
- ansible_ssh_user="root"
- ansible_ssh_pass="a"
- [[email protected] ansible]# ansible app --list-host //檢視
- hosts (4):
- web1
- web2
- db1
- db2
- [[email protected] ansible]# ansible app -m ping //測試
- web1 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- web2 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- db1 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- db2 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
步驟四:多路徑練習
自定義的ansible檔案只在當前路徑生效
1)多路徑
- [[email protected] ~]# mkdir aaa
- [[email protected] ~]# cd aaa/
- [[email protected] aaa]# vim myhost
- [app1]
- web1
- db1
- [app2]
- web2
- db2
- [app:children]
- app1
- app2
- [other]
- cache
- [app:vars]
- ansible_ssh_user="root"
- ansible_ssh_pass="a"
- [[email protected] aaa]# touch ansible.cfg
- [[email protected] aaa]# grep -Ev "^#|^$" /etc/ansible/ansible.cfg
- [defaults]
- roles_path = /etc/ansible/roles:/usr/share/ansible/roles
- host_key_checking = False
- [inventory]
- [privilege_escalation]
- [paramiko_connection]
- [ssh_connection]
- [persistent_connection]
- [accelerate]
- [selinux]
- [colors]
- [diff]
- [[email protected] aaa]# vim ansible.cfg
- [defaults]
- inventory = myhost
- host_key_checking = False
2)測試結果
- [[email protected] aaa]# ansible app1 -m ping
- web1 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- db1 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- [[email protected] aaa]# ansible app -m ping
- web1 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- db1 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- db2 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- web2 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- [[email protected] aaa]# ansible app --list-host
- hosts (4):
- web1
- db1
- web2
- db2
- [[email protected] aaa]# cd
- [[email protected] ~]# ansible app1 --list-host //切換到別的目錄,測試失敗
- [WARNING]: Could not match supplied host pattern, ignoring: app1
- [WARNING]: No hosts matched, nothing to do
- hosts (0):
3 案例3:動態主機
3.1 問題
本案例要求:
- 指令碼輸出主機列表
3.2 步驟
實現此案例需要按照如下步驟進行。
步驟一:指令碼輸出主機列表
- [[email protected] ~]# cd aaa
- [[email protected] aaa]# vim host.py
- #!/usr/bin/python
- import json
- hostlist = {}
- hostlist["bb"] = ["192.168.1.52", "192.168.1.53"]
- hostlist["192.168.1.54"] = {
- "ansible_ssh_user":"root","ansible_ssh_pass":"pwd"
- }
- hostlist["aa"] = {
- "hosts" : ["192.168.1.55", "192.168.1.56"],
- "vars" : {
- "ansible_ssh_user":"root","ansible_ssh_pass":"pwd"
- }
- }
- print(json.dumps(hostlist))
- [[email protected] aaa]# chmod 755 ./host.py
步驟二:指令碼輸出樣例(這樣寫輸出的結果有些亂)
- [[email protected] aaa]# ./host.py
- {"aa": {"hosts": ["192.168.1.55", "192.168.1.56"], "vars": {"ansible_ssh_user": "root", "ansible_ssh_pass": "a"}}, "192.168.1.54": {"ansible_ssh_user": "root", "ansible_ssh_pass": "a"}, "bb": ["192.168.1.52", "192.168.1.53"]}
步驟三:可以用shell指令碼輸出
- [[email protected] aaa]# vim my.sh
- #!/bin/bash
- echo '
- { "aa": {
- "hosts":
- ["192.168.1.55", "192.168.1.56"],
- "vars": {
- "ansible_ssh_user": "root",
- "ansible_ssh_pass": "a"}
- },
- }'
- [[email protected] aaa]# chmod 755 my.sh
- [[email protected] aaa]# ./my.sh
- { "aa": {
- "hosts":
- ["192.168.1.55", "192.168.1.56"],
- "vars": {
- "ansible_ssh_user": "root",
- "ansible_ssh_pass": "a"}
- },
- }
- [[email protected] aaa]# vim ansible.cfg
- [defaults]
- inventory = my.sh
- host_key_checking = False
- [[email protected] aaa]# ansible aa -m ping
- 192.168.1.55 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- 192.168.1.56 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
步驟二:批量執行
1)檢視負載
- [[email protected] aaa]# ansible app -m command -a 'uptime'
- db1 | SUCCESS | rc=0 >>
- 11:35:52 up 1:59, 2 users, load average: 0.00, 0.01, 0.01
- web1 | SUCCESS | rc=0 >>
- 11:35:52 up 2:00, 2 users, load average: 0.00, 0.01, 0.02
- db2 | SUCCESS | rc=0 >>
- 11:35:53 up 1:59, 2 users, load average: 0.00, 0.01, 0.03
- web2 | SUCCESS | rc=0 >>
- 11:35:52 up 1:59, 2 users, load average: 0.00, 0.01, 0.02
2)檢視時間
- [[email protected] aaa]# ansible app -m command -a 'date +%F\ %T'
- db1 | SUCCESS | rc=0 >>
- 2018-09-06 11:42:18
- web1 | SUCCESS | rc=0 >>
- 2018-09-06 11:42:18
- web2 | SUCCESS | rc=0 >>
- 2018-09-06 11:42:18
- db2 | SUCCESS | rc=0 >>
- 2018-09-06 11:42:19
4 案例4:批量部署證書檔案
4.1 問題
本案例要求:
- 建立一對金鑰
- 給所有主機部署金鑰
4.2 步驟
實現此案例需要按照如下步驟進行。
步驟一:批量部署證書檔案,給所有主機部署金鑰
1)建立金鑰
- [[email protected] aaa]# cd /root/.ssh/
- [[email protected] .ssh]# vi /etc/ansible/hosts
- [web]
- web1
- web2
- [db]
- db[1:2]
- [other]
- cache
- [[email protected] .ssh]# ansible all -m ping //直接ping會報錯
- [[email protected] .ssh]# ssh-keygen -t rsa -b 2048 -N '' //建立金鑰
2)給所有主機部署金鑰
- [[email protected] .ssh]# ansible all -m authorized_key -a "user=root exclusive=true manage_dir=true key='$(< /root/.ssh/id_rsa.pub)'" -k
- SSH password: //輸入密碼
- [[email protected] .ssh]# ansible all -m ping //成功
- web2 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- db2 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- web1 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- cache | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- db1 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
- [[email protected] .ssh]# ssh web1 //不需要輸入密碼,可以直接登陸
- Last login: Thu Sep 6 11:49:00 2018 from 192.168.1.51
- [[email protected] ~]#
5 案例5:練習模組
5.1 問題
本案例要求:
- 練習使用command , shell , raw, script模組
5.2 步驟
實現此案例需要按照如下步驟進行。
步驟一:練習模組
ansible-doc //模組的手冊,相當於man
ansible-doc -l //列出所有模組
ansible-doc 模組名 //檢視指定模組的幫助資訊
1)ping模組
- [[email protected] .ssh]# ansible web1 -m ping
- web1 | SUCCESS => {
- "changed": false,
- "ping": "pong"
- }
2)command模組
- [[email protected] .ssh]# ansible web1 -m command -a 'chdir=/tmp touch f1' //建立成功
- [[email protected] ~]# cd /tmp/
- [[email protected] tmp]# ls //在web1上面檢視
- f1
3)shell模組
- [[email protected] .ssh]# ansible web1 -m shell -a 'chdir=/tmp touch f2' //建立成功
- [[email protected] ~]# cd /tmp/
- [[email protected] tmp]# ls //在web1上面檢視
- f2
4)raw模組
- [[email protected] .ssh]# ansible web1 -m raw -a 'chdir=/tmp touch f3'
- //檔案可以建立,但無法切換目錄,檔案在使用者家目錄下生成
- web1 | SUCCESS | rc=0 >>
- Shared connection to web1 closed.
- [[email protected] tmp]# cd /root/
- [[email protected] ~]# ls //在web1上面檢視
- f3
5)script模組
對於太複雜的命令,可以寫個指令碼,然後用script模組執行
在web1主機上建立zhangsan3使用者,修改zhangsan3的密碼為123456,設定zhangsan3第一次登陸必須修改密碼
用命令寫:
- [[email protected] .ssh]# ansible web1 -m shell -a 'useradd zhangsan3'
- [[email protected] .ssh]# ansible web1 -m shell -a 'echo 123456 | passwd --stdin zhangsan3'
- [[email protected] .ssh]# ssh -l zhangsan3 web1
- [email protected]'s password: //輸入zhangsan3的密碼
- [[email protected] .ssh]# ansible web1 -m shell -a 'chage -d 0 zhangsan3'
- [[email protected] .ssh]# ssh -l zhangsan3 web1
用指令碼寫,script模組執行:
- [[email protected] .ssh]# vim user.sh
- #!/bin/bash
- useradd zhangsan3
- echo 123456 | passwd --stdin zhangsan3
- chage -d 0 zhangsan3
- echo
- [[email protected] .ssh]# ansible web1 -m script -a './user.sh'
- web1 | SUCCESS => {
- "changed": true,
- "rc": 0,
- "stderr": "Shared connection to web1 closed.\r\n",
- "stdout": "Changing password for user zhangsan3.\r\npasswd: all authentication tokens updated successfully.\r\n\r\n",
- "stdout_lines": [
- "Changing password for user zhangsan3.",
- "passwd: all authentication tokens updated successfully.",
- ""
- ]
- }
- [[email protected] .ssh]# ssh -l lisi web1
- [email protected]'s password:
- You are required to change your password immediately (root enforced)
- Last login: Thu Sep 6 14:51:33 2018 from 192.168.1.51
- WARNING: Your password has expired.
- You must change your password now and login again!
- Changing password for user lisi.
- Changing password for lisi.
- (current) UNIX password:
6 案例6:模組練習
6.1 問題
本案例要求:
- 使用copy模組同步資料
- 使用lineinfile模組編輯檔案
- 使用replace模組修改檔案
6.2 步驟
實現此案例需要按照如下步驟進行。
步驟一:模組練習
1)使用copy模組同步資料
src:要複製到程序主機的檔案在本地的地址,可以是絕對路徑,也可以是相對路徑。如果路徑是一個目錄,它將遞迴複製。在這種情況下,如果路徑使用"/"來結尾,則只複製目錄裡的內容,如果沒有使用"/"來結尾,則包含目錄在內的整個內容全部複製,類似於rsync
dest:必選項。程序主機的絕對路徑,如果原始檔是一個目錄,那麼該路徑也必須是個目錄
backup:在覆蓋之前將原檔案備份,備份檔案包含時間資訊。有兩個選項:yes|no
force:如果目標主機包含該檔案,但內容不同,如果設定為yes,則強制覆蓋,如果為no,則只有當目標主機的目標位置不存在該檔案時,才複製。預設為yes
- [[email protected] .ssh]# ansible all -m shell -a 'cat /etc/resolv.conf'
- //檢視/etc/resolv.conf
- cache | SUCCESS | rc=0 >>
- ; generated by /usr/sbin/dhclient-script
- nameserver 192.168.1.254
- search localhost
- db2 | SUCCESS | rc=0 >>
- ; generated by /usr/sbin/dhclient-script
- nameserver 192.168.1.254
- search localhost
- web1 | SUCCESS | rc=0 >>
- ; generated by /usr/sbin/dhclient-script
- nameserver 192.168.1.254
- search localhost
- web2 | SUCCESS | rc=0 >>
- ; generated by /usr/sbin/dhclient-script
- nameserver 192.168.1.254
- search localhost
- db1 | SUCCESS | rc=0 >>
- ; generated by /usr/sbin/dhclient-script
- nameserver 192.168.1.254
- search localhost
- [[email protected] .ssh]# vi /etc/resolv.conf
- nameserver 172.40.1.10
- [[email protected] .ssh]# ansible all -m copy -a 'src=/etc/resolv.conf dest=/etc/resolv.conf' //複製本機的resolv.conf到其他主機
- [[email protected] .ssh]# ansible all -m shell -a 'cat /etc/resolv.conf'
- //檢視有nameserver 172.40.1.10
- [[email protected] ~]# mkdir aa
- [[email protected] ~]# ansible all -m copy -a 'src=/root/aa dest=/root/a.log'
- //複製本機的目錄/root/aa到其他機器的/root/a.log,複製目錄只能少數批量執行同步
- [[email protected] ~]# ansible all -m shell -a 'ls -ld /root'
- db2 | SUCCESS | rc=0 >>
- dr-xr-x---. 4 root root 167 Sep 6 11:48 /root
- web2 | SUCCESS | rc=0 >>
- dr-xr-x---. 4 root root 167 Sep 6 11:48 /root
- cache | SUCCESS | rc=0 >>
- dr-xr-x---. 4 root root 177 Sep 6 14:35 /root
- db1 | SUCCESS | rc=0 >>
- dr-xr-x---. 4 root root 167 Sep 6 11:48 /root
- web1 | SUCCESS | rc=0 >>
- dr-xr-x---. 4 root root 177 Sep 6 14:35 /root
2)使用lineinfile模組編輯檔案
以行為基礎,整行修改(整行被替換掉)
- [[email protected] ~]# ansible cache -m lineinfile \
- -a 'path=/etc/sysconfig/network-scripts/ifcfg-eth0 \
- regexp="^ONBOOT=" line="ONBOOT=\"no\""'
- cache | SUCCESS => {
- "backup": "",
- "changed": true,
- "msg": "line replaced"
- }
3)使用replace模組修改檔案
修改檔案的某一部分(替換一行中匹配的內容),以正則表示式匹配為基礎修改
- [[email protected] ~]# ansible cache -m replace -a \
- 'path=/etc/sysconfig/network-scripts/ifcfg-eth0 \
- regexp="^(ONBOOT=).*" replace="\1\"yes\""'
- cache | SUCCESS => {
- "changed": true,
- "msg": "1 replacements made"
- }
7 案例7:綜合練習
7.1 問題
本案例要求:
- 安裝Apache並修改監聽埠為8080
- 修改ServerName配置,執行apachectl -t命令不報錯
- 設定預設主頁hello world
- 啟動服務並設開機自啟
7.2 步驟
實現此案例需要按照如下步驟進行。
步驟一:熟悉模組
1)yum模組
- [[email protected] ~]# ansible other -m yum -a 'name="lrzsz" state=removed'
- //lrzsz軟體包名,removed=absent刪除
- [[email protected] ~]# ansible other -m yum -a 'name="lrzsz,lftp" state=installed'
- //安裝多個軟體包,不寫state預設為安裝
2)service模組
- [[email protected] ~]# ansible other -m service -a 'name="sshd" enabled="yes" state="started"' //sshd服務名,開機啟動同時啟動這個服務
3)setup模組
filter 過濾指定的關鍵字(可以過濾到我們需要的資訊)
- [[email protected] ~]# ansible cache -m setup -a 'filter=os'
- cache | SUCCESS => {
- "ansible_facts": {},
- "changed": false
- }
- [[email protected] ~]# ansible cache -m setup -a 'filter=ansible_distribution'
- cache | SUCCESS => {
- "ansible_facts": {
- "ansible_distribution": "CentOS"
- },
- "changed": false
- }
步驟二:安裝Apache
1)安裝Apache服務設定開機自啟
- [[email protected] ~]# ansible cache -m yum -a 'name=httpd state=installed'
- [[email protected] ~]# ansible cache -m service -a 'name=httpd enabled=yes state=started'
2)修改埠號為8080
- [[email protected] ~]# ssh cache
- Last login: Thu Sep 6 15:30:33 2018 from 192.168.1.51
- [[email protected] ~]# cat /etc/httpd/conf/httpd.conf | grep Listen
- Listen 80
- [[email protected] ~]# ansible cache -m lineinfile -a 'path="/etc/httpd/conf/httpd.conf" regexp="^Listen " line="Listen 8080"'cache | SUCCESS => {
- "backup": "",
- "changed": true,
- "msg": "line replaced"
- }
- [[email protected] ~]# ssh cache
- Listen 8080
步驟三:修改ServerName配置,執行apachectl -t命令不報錯
1)沒有修改之前
- [[email protected] ~]# apachectl -t //有報錯
- AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.1.56. Set the 'ServerName' directive globally to suppress this message
- Syntax OK
2)修改之後
- [[email protected] ~]# ansible cache -m lineinfile -a 'path="/etc/httpd/conf/httpd.conf" regexp="^ServerName " line="ServerName 0.0.0.0"'
- cache | SUCCESS => {
- "backup": "",
- "changed": true,
- "msg": "line added"
- }
- [[email protected] ~]# ssh cache
- Last login: Thu Sep 6 15:36:08 2018 from 192.168.1.51
- [[email protected] ~]# apachectl -t
- Syntax OK
步驟四:設定預設主頁為hello world
- [[email protected] ~]# ansible cache -m copy -a 'src=/root/index.html dest=/var/www/html/index.html' ///root/index.html這個頁面可以自己寫
- cache | SUCCESS => {
- "changed": true,
- "checksum": "22596363b3de40b06f981fb85d82312e8c0ed511",
- "dest": "/var/www/html/index.html",
- "gid": 0,
- "group": "root",
- "md5sum": "6f5902ac237024bdd0c176cb93063dc4",
- "mode": "0644",
- "owner": "root",
- "size": 12,
- "src": "/root/.ansible/tmp/ansible-tmp-1536219767.29-30682157793478/source",
- "state": "file",
- "uid": 0
- }