Ansibleバッチ管理自動化ツール - 研究ノート

Ansibleバッチ管理自動化ツール

1 Ansibleはじめに

1.1 ansibleについて

  • バッチ管理サーバー・ツール
  • SSHによって管理エージェントを展開する必要はありません、
  • 操作や人気の自動化ツールのメンテナンスます。https://github.com/ansible/ansible

1.2設置環境を確認します

[root@ansible ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)

[root@ansible ~]# uname -r
3.10.0-1062.4.3.el7.x86_64

#python版本需要2.6以上,不过通过centos7都会默认安装上python2.7.5
[root@ansible ~]# python -V
Python 2.7.5

パスワードなしで公開鍵と秘密鍵のsshを達成するために、2の構成

  • ansibleは全く薬ではありません、エージェントがどのようにバッチ管理サーバではないでしょうか?主にバッチ管理サーバーへのsshを借りました。
  • sshのデフォルトのログインパスワードは管理が面倒であるように、必要とされ、このレッスンでは、パスワードなしでSSHを導入することです。
  • パスワードなしでsshがansibleバッチ管理サーバが簡単になる使用して、後で実現しました
ホスト名 IP
ansible 192.168.200.27
WEB01 192.168.200.28
WEB02 192.168.200.29

2.1鍵ペアの生成

[root@ansible ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ""
Generating public/private rsa key pair.
Created directory '/root/.ssh'.
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:g2QJQiBD4PRiGYf1ARed89NGH4CnceXzRP/VCJEJq9w root@ansible
The key's randomart image is:
+---[RSA 2048]----+
|B*=+o+o . oo== . |
|+o=.o..= o =+o..o|
| = . .+ o O .oo.+|
|. .  o o * o .+ o|
|      . S E    ..|
|         .       |
|                 |
|                 |
|                 |
+----[SHA256]-----+

2.2それぞれWEB01とWEB02にキーを配布

[root@ansible ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 192.168.200.28
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 123.123

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh -o ' StrictHostKeyChecking=no' '192.168.200.28'"
and check to make sure that only the key(s) you wanted were added.

2.3パスワードのないログインテストに

[root@ansible ~]# hostname -I
192.168.200.27 
[root@ansible ~]# ssh 192.168.200.28
Last login: Sun Dec 22 18:28:34 2019 from 192.168.200.1
[root@web01 ~]# hostname -I
192.168.200.28 

Ansibleをインストール3。

yumの3.1 ansibleソフトウェアをインストールします

[root@ansible ~]# yum -y install ansible

#查看ansible的版本
[root@ansible ~]# 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  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

3.2変更ansibleプロファイル(単一ノード)

[root@ansible ~]# cd /etc/ansible/
[root@ansible ansible]# vim hosts
[root@ansible ansible]# cat hosts
[Web01]
192.168.200.28
[Web02]
192.168.200.29

3.3 ansible実行コマンド遠隔試験

[root@ansible ansible]# ansible Web01 -m ping
192.168.200.28 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

[root@ansible ansible]# ansible Web02 -m ping
192.168.200.29 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
[root@ansible ansible]# ansible Web01 -a "uname -r"
192.168.200.28 | SUCCESS | rc=0 >>
3.10.0-1062.el7.x86_64

3.4 ansible変更の設定ファイル(マルチノード)

[root@ansible ansible]# vim hosts
[root@ansible ansible]# tail -3 hosts
[all]
192.168.200.28
192.168.200.29

3.5 ansibleリモートコマンドテストを実行して行います

[root@ansible ansible]# ansible all -a "uname -r"
192.168.200.28 | SUCCESS | rc=0 >>
3.10.0-1062.el7.x86_64

192.168.200.29 | SUCCESS | rc=0 >>
3.10.0-1062.4.3.el7.x86_64

4. Ansibleコマンドモジュール

4.1 ansible moduleコマンドを(お勧めしません、パイプラインはリダイレクトをサポートしていませんサポートしていません)

パラメータ-m:モジュール名
パラメータ-a:直接コマンドで(コマンドがサポートされていません)

#command支持直接回显命令的执行结果
[root@ansible ~]# ansible all -m command -a "pwd"
192.168.200.28 | SUCCESS | rc=0 >>
/root

192.168.200.29 | SUCCESS | rc=0 >>
/root
#command模块不支持重定向操作
[root@ansible ~]# ansible all -m command -a "echo ywb >> /tmp/hyx"
192.168.200.28 | SUCCESS | rc=0 >>
ywb >> /tmp/hyx

192.168.200.29 | SUCCESS | rc=0 >>
ywb >> /tmp/hyx
#command模块不支持管道符操作
[root@ansible ~]# ansible all -m command -a "echo ywb | grep w"
192.168.200.28 | SUCCESS | rc=0 >>
ywb | grep w

192.168.200.29 | SUCCESS | rc=0 >>
ywb | grep w
[root@ansible ~]# ansible all -a 'tail -1 /etc/passwd'
192.168.200.29 | SUCCESS | rc=0 >>
chrony:x:998:996::/var/lib/chrony:/sbin/nologin

192.168.200.28 | SUCCESS | rc=0 >>
chrony:x:998:996::/var/lib/chrony:/sbin/nologin

4.2 ansibleモジュールシェル(支柱、支持リダイレクション)

#shell支持重定向
[root@ansible ~]# ansible all -m shell -a "echo ywb >> /tmp/hyx"
192.168.200.29 | SUCCESS | rc=0 >>

192.168.200.28 | SUCCESS | rc=0 >>
#shell模块支持管道符
[root@ansible ~]# ansible all -m shell -a "echo ywb | grep w"
192.168.200.28 | SUCCESS | rc=0 >>
ywb

192.168.200.29 | SUCCESS | rc=0 >>
ywb

4.3ピングモジュール

#ping,模块是用来检测指定主机的连通性。
[root@ansible ~]# ansible all -m ping
192.168.200.28 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
192.168.200.29 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

4.4のcronモジュール

cronのモジュールは、ミッションプランを定義するために使用されます。二つの状態(状態)があり、前記本を追加(デフォルトではない状態)を表すが、不在で除去表します。

#添加任务计划
[root@ansible ~]# ansible Web01 -m cron -a 'minute="*/1" job="/bin/echo heihei" name="ceshi"'
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "envs": [], 
    "jobs": [
        "ceshi"
    ]
}

#检查是否添加成功
[root@ansible ~]# ansible Web01 -a "crontab -l"
192.168.200.28 | SUCCESS | rc=0 >>
#Ansible: ceshi
*/1 * * * * /bin/echo heihei

#查看Wbe01组的主机查看
[root@ansible ~]# ansible Web01 -a "tail -2 /var/spool/mail/root "
192.168.200.28 | SUCCESS | rc=0 >>
heihei
#移除任务计划
[root@ansible ~]# ansible Web01 -m cron -a 'name="ceshi" state=absent'
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "envs": [], 
    "jobs": []
}

#检查定时任务是否移除成功
[root@ansible ~]# ansible Web01 -a "crontab -l"
192.168.200.28 | SUCCESS | rc=0 >>

4.5ユーザモジュール

ユーザモジュールは、新しいユーザーや変更には、delete既存のユーザーを作成するために使用されます。どこnameオプションは、作成したユーザー名を指定するために使用されます。リクエストがuseraddコマンドで、userdelのは、3つの命令をUSERMOD

#创建用户
[root@ansible ~]# ansible Web01 -m user -a 'name="ywb"'
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "comment": "", 
    "createhome": true, 
    "group": 1000, 
    "home": "/home/ywb", 
    "name": "ywb", 
    "shell": "/bin/bash", 
    "state": "present", 
    "system": false, 
    "uid": 1000
}

#检查用户是否创建成功
[root@ansible ~]# ansible Web01 -a 'id ywb'
192.168.200.28 | SUCCESS | rc=0 >>
uid=1000(ywb) gid=1000(ywb) 组=1000(ywb)
#删除用户
[root@ansible ~]# ansible Web01 -m user -a 'name="ywb" state=absent'
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "force": false, 
    "name": "ywb", 
    "remove": false, 
    "state": "absent"
}

#检查用户是否删除成功
[root@ansible ~]# ansible Web01 -a 'id ywb'
192.168.200.28 | FAILED | rc=1 >>
id: ywb: no such usernon-zero return code

4.6グループ・モジュール

グループは、ユーザーグループを管理するための手段。要求は、groupaddのgroupdelグループ、3つの命令をgroupmodのさ。

#创建用户组
[root@ansible ~]# ansible Web01 -m group -a 'name=hyx gid=306 system=yes'
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "gid": 306, 
    "name": "hyx", 
    "state": "present", 
    "system": true
}

#检查是否创建成功
[root@ansible ~]# ansible Web01 -a 'tail -1 /etc/group'
192.168.200.28 | SUCCESS | rc=0 >>
hyx:x:306:
#将用户ywb添加到hyx组中
[root@ansible ~]# ansible Web01 -m user -a 'name=ywb uid=306 system=yes group=hyx'
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "comment": "", 
    "createhome": true, 
    "group": 306, 
    "home": "/home/ywb", 
    "name": "ywb", 
    "shell": "/bin/bash", 
    "state": "present", 
    "system": true, 
    "uid": 306
}

#查看用户ywb是否添加到hyx组中
[root@ansible ~]# ansible Web01 -a 'tail -1 /etc/passwd'
192.168.200.28 | SUCCESS | rc=0 >>
ywb:x:306:306::/home/ywb:/bin/bash

4.7コピーモジュール

コピーモジュールは、ファイル複製のために使用され、バッチは、文書を発行しました。SRCファイルのパスは、ローカルのソースを定義するために、請求項DESTコンテンツを指定することで、ターゲットコンテンツファイルを生成するために使用された管理対象ホストのファイル・パスを使用して定義されました。

#将本地文件/etc/fstab复制到被管理主机上的/tmp/fstab.bak,将所有者设置为root,权限设置为644.
[root@ansible ~]# ansible Web01 -m copy -a 'src=/etc/fstab dest=/tmp/fstab.bak owner=root mode=644'
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "checksum": "aa95f6ca1f678dcfadb671a29a3cfcc5610ac5b9", 
    "dest": "/tmp/fstab.bak", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "6bd26227e6a9b79520d2e4c55e232780", 
    "mode": "0644", 
    "owner": "root", 
    "size": 473, 
    "src": "/root/.ansible/tmp/ansible-tmp-1578033751.3-3069697382672/source", 
    "state": "file", 
    "uid": 0
}

#查看是否存在复制的文件
[root@ansible ~]# ansible Web01 -a "ls -d /tmp/fstab.bak"
192.168.200.28 | SUCCESS | rc=0 >>
/tmp/fstab.bak
#将hello写入/tmp/fstab.back
[root@ansible ~]# ansible Web01 -m copy -a 'content="hello" dest=/tmp/fstab.bak'
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "checksum": "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d", 
    "dest": "/tmp/fstab.bak", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "5d41402abc4b2a76b9719d911017c592", 
    "mode": "0644", 
    "owner": "root", 
    "size": 5, 
    "src": "/root/.ansible/tmp/ansible-tmp-1578033973.42-101266898343089/source", 
    "state": "file", 
    "uid": 0
}

#查看内容是否写入
[root@ansible ~]# ansible Web01 -a 'cat /tmp/fstab.bak'
192.168.200.28 | SUCCESS | rc=0 >>
hello

4.8ファイルモジュール

ファイル・モジュールは、ファイル属性を設定します。パスは、名前やシンボリックリンクは、ファイルを置き換えるために作成されたを使用してDEST、ソースファイルパスsrcを定義するために使用されるファイルのパスを指定します。

#设置文件/tmp/fstab.back的所属主为ywb,所属组为hyx,权限为755.
[root@ansible ~]# ansible Web01 -m file -a 'owner=ywb group=hyx mode=755 path=/tmp/fstab.bak'
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "gid": 306, 
    "group": "hyx", 
    "mode": "0755", 
    "owner": "ywb", 
    "path": "/tmp/fstab.bak", 
    "size": 5, 
    "state": "file", 
    "uid": 306
}

#查看文件的属性
[root@ansible ~]# ansible Web01 -a 'ls -l /tmp/fstab.bak'
192.168.200.28 | SUCCESS | rc=0 >>
-rwxr-xr-x 1 ywb hyx 5 1月   3 14:46 /tmp/fstab.bak
#设置/tmp/fstab.link为/tmp/fstab.bak的链接文件
[root@ansible ~]# ansible Web01 -m file -a 'path=/tmp/fstab.bak.link src=/tmp/fstab.bak state=link'
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "dest": "/tmp/fstab.bak.link", 
    "gid": 0, 
    "group": "root", 
    "mode": "0777", 
    "owner": "root", 
    "size": 14, 
    "src": "/tmp/fstab.bak", 
    "state": "link", 
    "uid": 0
}

#检查软连接是否创建成功
[root@ansible ~]# ansible Web01 -a 'ls -l /tmp/fstab.bak /tmp/fstab.bak.link'
192.168.200.28 | SUCCESS | rc=0 >>
-rwxr-xr-x 1 ywb  hyx   5 1月   3 14:46 /tmp/fstab.bak
lrwxrwxrwx 1 root root 14 1月   4 17:51 /tmp/fstab.bak.link -> /tmp/fstab.bak
#删除文件/tmp/fstab.bak
[root@ansible ~]# ansible Web01 -m file -a "path=/tmp/fstab.bak state=absent"
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "path": "/tmp/fstab.bak", 
    "state": "absent"
}
#创建文件/tmp/test
[root@ansible ~]# ansible Web01 -m file -a "path=/tmp/test state=touch"
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "dest": "/tmp/test", 
    "gid": 0, 
    "group": "root", 
    "mode": "0644", 
    "owner": "root", 
    "size": 0, 
    "state": "file", 
    "uid": 0
}

4.9スクリプトモジュール

スクリプトモジュールは、管理対象ホスト上でローカルに実行するスクリプトをコピーすることができます。相対パスの使用は、スクリプトを指定することに留意すべきです。

#例如,编辑一个本地脚本test.sh,复制到被管理主机上运行。
[root@ansible ~]# vim /tmp/test.sh
[root@ansible ~]# cat /tmp/test.sh 
#!/bin/bash
echo "hello" > /tmp/script.txt
[root@ansible ~]# chmod +x /tmp/test.sh
[root@ansible ~]# ll -d /tmp/test.sh 
-rwxr-xr-x 1 root root 43 1月   4 18:04 /tmp/test.sh

[root@ansible ~]# ansible Web01 -m script -a '/tmp/test.sh'
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "rc": 0, 
    "stderr": "Shared connection to 192.168.200.28 closed.\r\n", 
    "stdout": "", 
    "stdout_lines": []
}

#查看脚本实现
[root@ansible ~]# ansible Web01 -a "cat /tmp/script.txt"
192.168.200.28 | SUCCESS | rc=0 >>
hello

4.10 ansibleモジュール生、コマンドを実行するための最も原始的な方法(sshのみによって達成されるのpythonを、信頼しません)

#清除yum缓存
[root@ansible ~]# ansible all -m raw -a "yum -y clean all"
192.168.200.29 | SUCCESS | rc=0 >>
已加载插件:fastestmirror
正在清理软件源: base extras updates
Shared connection to 192.168.200.29 closed.


192.168.200.28 | SUCCESS | rc=0 >>
已加载插件:fastestmirror
正在清理软件源: base extras updates
Shared connection to 192.168.200.28 closed.
#建立yum缓存
[root@ansible ~]# ansible all -m raw -a "yum makecache"
192.168.200.29 | SUCCESS | rc=0 >>
已加载插件:fastestmirror
Determining fastest mirrors
 * base: mirrors.huaweicloud.com
 * extras: mirrors.huaweicloud.com
 * updates: mirror.bit.edu.cn
base                                                     | 3.6 kB     00:00     
extras                                                   | 2.9 kB     00:00     
updates                                                  | 2.9 kB     00:00     
(1/10): base/7/x86_64/group_gz                             | 165 kB   00:00     
(2/10): extras/7/x86_64/filelists_db                       | 207 kB   00:01     
(3/10): extras/7/x86_64/other_db                           | 100 kB   00:00     
(4/10): extras/7/x86_64/primary_db                         | 153 kB   00:01     
(5/10): base/7/x86_64/other_db                             | 2.6 MB   00:03     
(6/10): base/7/x86_64/primary_db                           | 6.0 MB   00:05     
(7/10): updates/7/x86_64/filelists_db                      | 3.3 MB   00:03     
(8/10): updates/7/x86_64/primary_db                        | 5.8 MB   00:07     
(9/10): base/7/x86_64/filelists_db                         | 7.3 MB   00:21     
(10/10): updates/7/x86_64/other_db                         | 363 kB   00:24     
元数据缓存已建立
Shared connection to 192.168.200.29 closed.


192.168.200.28 | SUCCESS | rc=0 >>
已加载插件:fastestmirror
Determining fastest mirrors
 * base: mirrors.neusoft.edu.cn
 * extras: mirrors.neusoft.edu.cn
 * updates: mirrors.njupt.edu.cn
base                                                     | 3.6 kB     00:00     
extras                                                   | 2.9 kB     00:00     
updates                                                  | 2.9 kB     00:00     
(1/10): extras/7/x86_64/filelists_db                       | 207 kB   00:01     
(2/10): base/7/x86_64/other_db                             | 2.6 MB   00:01     
(3/10): extras/7/x86_64/other_db                           | 100 kB   00:00     
(4/10): extras/7/x86_64/primary_db                         | 153 kB   00:00     
(5/10): base/7/x86_64/group_gz                             | 165 kB   00:04     
(6/10): updates/7/x86_64/other_db                          | 363 kB   00:00     
(7/10): base/7/x86_64/primary_db                           | 6.0 MB   00:04     
(8/10): updates/7/x86_64/filelists_db                      | 3.3 MB   00:07     
(9/10): updates/7/x86_64/primary_db                        | 5.8 MB   00:17     
(10/10): base/7/x86_64/filelists_db                        | 7.3 MB   00:39     
元数据缓存已建立
Shared connection to 192.168.200.28 closed.

4.11 YUMモジュール

yumのモジュールを多重化する責任は、パッケージ名をインストールするには管理ホストとアンロードのパッケージにインストールされ、現在、指定された状態にインストールパッケージの状態を使用して表現するために、最新のインストールを指定し、無負荷欠席表明しました。

#安装zsh软件包(zsh命令参考链接https://zhuanlan.zhihu.com/p/63585679)
[root@ansible ~]# ansible Web01 -m yum -a 'name=zsh'
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * base: mirrors.aliyun.com\n * extras: mirrors.huaweicloud.com\n * updates: mirrors.aliyun.com\nResolving Dependencies\n--> Running transaction check\n---> Package zsh.x86_64 0:5.0.2-33.el7 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package        Arch              Version                 Repository       Size\n================================================================================\nInstalling:\n zsh            x86_64            5.0.2-33.el7            base            2.4 M\n\nTransaction Summary\n================================================================================\nInstall  1 Package\n\nTotal download size: 2.4 M\nInstalled size: 5.6 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Installing : zsh-5.0.2-33.el7.x86_64                                      1/1 \n  Verifying  : zsh-5.0.2-33.el7.x86_64                                      1/1 \n\nInstalled:\n  zsh.x86_64 0:5.0.2-33.el7                                                     \n\nComplete!\n"
    ]
}

#查看是否安装成功
[root@ansible ~]# ansible Web01 -a 'rpm -q zsh'
 [WARNING]: Consider using yum, dnf or zypper module rather than running rpm

192.168.200.28 | SUCCESS | rc=0 >>
zsh-5.0.2-33.el7.x86_64
#卸载zsh软件包
[root@ansible ~]# ansible Web01 -m yum -a 'name=zsh state=absent'
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "已加载插件:fastestmirror\n正在解决依赖关系\n--> 正在检查事务\n---> 软件包 zsh.x86_64.0.5.0.2-33.el7 将被 删除\n--> 解决依赖关系完成\n\n依赖关系解决\n\n================================================================================\n Package       架构             版本                      源               大小\n================================================================================\n正在删除:\n zsh           x86_64           5.0.2-33.el7              @base           5.6 M\n\n事务概要\n================================================================================\n移除  1 软件包\n\n安装大小:5.6 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  正在删除    : zsh-5.0.2-33.el7.x86_64                                     1/1 \n  验证中      : zsh-5.0.2-33.el7.x86_64                                     1/1 \n\n删除:\n  zsh.x86_64 0:5.0.2-33.el7                                                     \n\n完毕!\n"
    ]
}

4.12サービスモジュール

状態管理サービスの動作を制御するためのサービスモジュール。どの状態サービスのステータスの使用を指定し、名前定義されたサービス名を使用して、最初からブート、値が真か偽であるかどうかを示す有効、値は、それぞれ、開始立ち止まっ、再起動されます。

#启动httpd服务并设置开机自启动。
[root@ansible ~]# ansible Web01 -m service -a 'enabled=true name=httpd state=started'
192.168.200.28 | SUCCESS => {
    "changed": true, 
    "enabled": true, 
    "name": "httpd", 
    "state": "started", 
    "status": {
        "ActiveEnterTimestampMonotonic": "0", 
        "ActiveExitTimestampMonotonic": "0", 
        "ActiveState": "inactive", 
        "After": "tmp.mount nss-lookup.target -.mount system.slice network.target remote-fs.target systemd-journald.socket basic.target", 
        "AllowIsolate": "no", 
        "AmbientCapabilities": "0", 
#以下省略若干。。。
   

#查看httpd的状态
[root@ansible ~]# ansible Web01 -a 'systemctl status httpd'
192.168.200.28 | SUCCESS | rc=0 >>
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 日 2020-01-05 16:28:58 CST; 1min 9s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 1673 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─1673 /usr/sbin/httpd -DFOREGROUND
           ├─1674 /usr/sbin/httpd -DFOREGROUND
           ├─1675 /usr/sbin/httpd -DFOREGROUND
           ├─1676 /usr/sbin/httpd -DFOREGROUND
           ├─1677 /usr/sbin/httpd -DFOREGROUND
           └─1678 /usr/sbin/httpd -DFOREGROUND

1月 05 16:28:52 web01 systemd[1]: Starting The Apache HTTP Server...
1月 05 16:28:56 web01 httpd[1673]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:feb5:5280. Set the 'ServerName' directive globally to suppress this message
1月 05 16:28:58 web01 systemd[1]: Started The Apache HTTP Server.

4.13セットアップ・モジュール

セットアップモジュールは、収集した事実の管理対象ホストを表示します。管理コマンドの各管理対象ホストへのアクセスの前にして実行し、コントロールパネルに送信される情報(オペレーティングシステム、IPアドレス)を所有します

#例如,查看Web01组的facts信息
root@ansible ~]# ansible Web01 -m setup
192.168.200.28 | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.200.28"
        ], 
        "ansible_all_ipv6_addresses": [
            "fe80::20c:29ff:feb5:5280"
        ], 
        "ansible_apparmor": {
            "status": "disabled"
        }, 
        "ansible_architecture": "x86_64", 
        "ansible_bios_date": "07/02/2015", 
        "ansible_bios_version": "6.00", 
        "ansible_cmdline": {
            "BOOT_IMAGE": "/vmlinuz-3.10.0-1062.el7.x86_64", 
            "LANG": "zh_CN.UTF-8", 
            "crashkernel": "auto", 
            "quiet": true, 
            "rd.lvm.lv": "centos_ywb/swap", 
            "rhgb": true, 
            "ro": true, 
            "root": "/dev/mapper/centos_ywb-root"
        }, 
#以下省略若干。。。

します。https://blog.51cto.com/11134648/2153774からドキュメントの共有部分

おすすめ

転載: www.cnblogs.com/ywb123/p/12152817.html