1. 程式人生 > >Ansible 學習之常用模組

Ansible 學習之常用模組

模組相關命令

(1)列出 ansible 支援的模組

ansible-doc -l

(2)檢視該模組的幫助資訊

ansible-doc ping # 檢視 ping 模組的幫助資訊

以下實驗均是在 IP 地址為: 192.168.91.128 的虛擬機器上操作的。
/etc/ansible/hosts 檔案中配置如下:

# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
# - Blank lines are ignored # - Groups of hosts are delimited by [header] elements # - You can enter hostnames or ip addresses # - A hostname/ip can be a member of multiple groups # Ex 1: Ungrouped hosts, specify before any group headers. ## green.example.com ## blue.example.com ## 192.168.100.1
## 192.168.100.10 [Client] 192.168.91.130 # Ex 2: A collection of hosts belonging to the 'webservers' group ## [webservers] ## alpha.example.org ## beta.example.org ## 192.168.1.100 ## 192.168.1.110 # If you have multiple hosts following a pattern you can specify # them like this: ## www[001:006].example.com
# Ex 3: A collection of database servers in the 'dbservers' group ## [dbservers] ## ## db01.intranet.mydomain.net ## db02.intranet.mydomain.net ## 10.25.1.56 ## 10.25.1.57 # Here's another example of host ranges, this time there are no # leading 0s: ## db-[99:101]-node.example.com

常用模組示例

ping 模組

檢查指定節點機器能否連通,如果主機線上,則回覆pong。
例如:

[root@xdhuxc ~]# ansible Client -m ping
192.168.91.130 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
[root@xdhuxc ~]# 
遠端命令模組(command、script、shell)

command 作為 ansible 的預設模組,可以執行遠端許可權範圍所有的 shell 命令,不支援管道符。
例如:

ansible Client -m command -a "free -h" # 檢視 Client 分組主機記憶體使用情況。

執行結果為:

[root@xdhuxc ~]# ansible Client -m command -a "free -h"
192.168.91.130 | SUCCESS | rc=0 >>
              total        used        free      shared  buff/cache   available
Mem:           976M        153M        599M        6.7M        223M        638M
Swap:          2.0G          0B        2.0G

script 的功能是在遠端主機執行主控端儲存的 shell 指令碼檔案,相當於 scp + shell 組合。
例如:

ansible Client -m script -a "/root/xdhuxc.sh string buffer"   # 遠端執行本地指令碼。

xdhuxc.sh 指令碼的內容為:

[[email protected] ~]# pwd
/root
[[email protected] ~]# ls
xdhuxc.sh
[[email protected] ~]# cat xdhuxc.sh 
#!/usr/bin/env bash
echo "Hello Shell."
echo $1
echo $2 >> /root/abc.sh

執行結果為:

[root@xdhuxc ~]# ansible Client -m script -a "/root/xdhuxc.sh string buffer"
192.168.91.130 | SUCCESS => {
    "changed": true, 
    "rc": 0, 
    "stderr": "Shared connection to 192.168.91.130 closed.\r\n", 
    "stdout": "Hello Shell.\r\nstring\r\n", 
    "stdout_lines": [
        "Hello Shell.", 
        "string"
    ]
}

在 192.168.91.130上,在 root 目錄下,會產生 abc.sh 檔案。

[root@xdhuxc ~]# pwd
/root
[root@xdhuxc ~]# ls
abc.sh  anaconda-ks.cfg  ~None
[root@xdhuxc ~]# cat abc.sh 
buffer
[root@xdhuxc ~]# 

~None 目錄下

[root@xdhuxc ~None]# pwd
/root/~None
[root@xdhuxc ~None]# tree -a
.
└── .ansible
    └── tmp

2 directories, 0 files

shell 的功能是執行遠端主機上的 shell 指令碼檔案,支援管道符。
例如:

ansible Client -m shell -a "/root/xdhuxc.sh" # 執行遠端機器上的指令碼。

在 root 目錄下建立 xdhuxc.sh 檔案,

[[email protected] ~]# pwd
/root
[[email protected] ~]# ll
total 12
-rw-r--r--  1 root root    7 Jun 11 22:19 abc.sh
-rw-------. 1 root root 1424 Apr  9 21:56 anaconda-ks.cfg
drwx------  3 root root   22 Jun 10 11:55 ~None
-rw-r--r--  1 root root   43 Jun 11 22:34 xdhuxc.sh   # xdhuxc.sh 沒有執行許可權。
[[email protected] ~]# cat xdhuxc.sh 
#!/usr/bin/env bash
echo -n "Hello World!"

在 xdhuxc.sh 沒有被賦予執行許可權時,執行 ansible 命令。

[root@xdhuxc ~]# ansible Client -m shell -a "/root/xdhuxc.sh"
192.168.91.130 | FAILED | rc=126 >>
/bin/sh: /root/xdhuxc.sh: Permission deniednon-zero return code

很明顯,xdhuxc.sh 沒有可執行許可權導致的,修改該命令,重新執行,命令執行成功。

[[email protected] ~]# ansible Client -m shell -a "chmod +x /root/xdhuxc.sh ; /root/xdhuxc.sh"
 [WARNING]: Consider using the file module with mode rather than running chmod.  If you need to use command because
file is insufficient you can add warn=False to this command task or set command_warnings=False in ansible.cfg to
get rid of this message.

192.168.91.130 | SUCCESS | rc=0 >>
Hello World!
copy 模組

copy 模組用於實現主控端向目標機器複製檔案,類似於 scp 功能。
例如:

ansible Client -m copy -a "src=/root/xdhuxc.sh dest=/tmp/ owner=root group=root mode=0755" # 向 Client 組中主機複製 xdhuxc.sh 到 /tmp 目錄下,檔案屬主、屬組都為 root,許可權為:0755

執行結果如下:

[root@xdhuxc ~]# pwd
/root
[root@xdhuxc ~]# ls
xdhuxc.sh
[root@xdhuxc ~]# ansible Client -m copy -a "src=/root/xdhuxc.sh dest=/tmp/ owner=root group=root mode=0755"
192.168.91.130 | SUCCESS => {
    "changed": true, 
    "checksum": "406eb4b32e5fe321308cfd40365f765685d64d58", 
    "dest": "/tmp/xdhuxc.sh", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "1abf4cb799e8858ab96bb7035837f248", 
    "mode": "0755", 
    "owner": "root", 
    "size": 72, 
    "src": "~None/.ansible/tmp/ansible-tmp-1528728245.0-152168028566440/source", 
    "state": "file", 
    "uid": 0
}

在 192.168.91.130 機器上

[root@xdhuxc ~None]# pwd
/root/~None
[root@xdhuxc ~None]# tree -a
.
└── .ansible
    └── tmp
        └── ansible-tmp-1528728229.03-131422320501562

3 directories, 0 files
[root@xdhuxc ~None]# ls /tmp
xdhuxc.sh
stat 模組

stat 模組用於獲取遠端檔案狀態資訊,atime/ctime/mtime/md5/uid/gid等資訊。
例如:

ansible Client -m stat -a "path=/etc/sysctl.conf"

執行結果如下:

[root@xdhuxc ~]# ansible Client -m stat -a "path=/etc/resolv.conf"
192.168.91.130 | SUCCESS => {
    "changed": false, 
    "stat": {
        "atime": 1528725838.9349997, 
        "attr_flags": "", 
        "attributes": [], 
        "block_size": 4096, 
        "blocks": 8, 
        "charset": "us-ascii", 
        "checksum": "dfebfbbbb5ea787130ffb53eaab925c743f50a56", 
        "ctime": 1528725836.281, 
        "dev": 64768, 
        "device_type": 0, 
        "executable": false, 
        "exists": true, 
        "gid": 0, 
        "gr_name": "root", 
        "inode": 17073255, 
        "isblk": false, 
        "ischr": false, 
        "isdir": false, 
        "isfifo": false, 
        "isgid": false, 
        "islnk": false, 
        "isreg": true, 
        "issock": false, 
        "isuid": false, 
        "mimetype": "text/plain", 
        "mode": "0644", 
        "mtime": 1528725836.281, 
        "nlink": 1, 
        "path": "/etc/resolv.conf", 
        "pw_name": "root", 
        "readable": true, 
        "rgrp": true, 
        "roth": true, 
        "rusr": true, 
        "size": 73, 
        "uid": 0, 
        "version": "1617439728", 
        "wgrp": false, 
        "woth": false, 
        "writeable": true, 
        "wusr": true, 
        "xgrp": false, 
        "xoth": false, 
        "xusr": false
    }
}

顯示了 /etc/sysctl.conf 檔案的所有狀態資訊。

get_url 模組

get_url 模組可以實現從遠端主機下載指定 URL 到本地,支援 sha256sum 檔案教驗。
例如:

ansible Client -m get_url -a "url=http://www.baidu.com dest=/tmp/index.html mode=0440 force=yes"

執行命令的結果為:

[root@xdhuxc ~]# ansible Client -m get_url -a "url=http://www.baidu.com dest=/tmp/index.html mode=0440 force=yes"
192.168.91.130 | SUCCESS => {
    "changed": true, 
    "checksum_dest": "69676fdd06a44063439b46a7df1e326eeae98ed4", 
    "checksum_src": "063ec2b31e5fa4d889076b948994ed4934d8ad62", 
    "dest": "/tmp/index.html", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "b4715e7fb51d60a983e29f3dc6d7a51a", 
    "mode": "0440", 
    "msg": "OK (unknown bytes)", 
    "owner": "root", 
    "size": 117044, 
    "src": "/tmp/tmpXgrOKe", 
    "state": "file", 
    "status_code": 200, 
    "uid": 0, 
    "url": "http://www.baidu.com"
}
[root@xdhuxc ~]# ansible Client -m command -a "ls /tmp"
192.168.91.130 | SUCCESS | rc=0 >>
ansible_EsBCHn
index.html                              # 下載下來的檔案                         
yum 模組

yum 模組用於實現軟體包管理。
例如:

ansible Client -m yum -a "name=curl state=latest"

命令執行的結果為:

[[email protected] ~]# ansible Client -m yum -a "name=curl state=latest"
192.168.91.130 | SUCCESS => {
    "changed": true, 
    "msg": "Repository base is listed more than once in the configuration\nRepository updates is listed more than once in the configuration\nRepository extras is listed more than once in the configuration\nRepository centosplus is listed more than once in the configuration\nRepository base is listed more than once in the configuration\nRepository updates is listed more than once in the configuration\nRepository extras is listed more than once in the configuration\nRepository centosplus is listed more than once in the configuration\nRepository base is listed more than once in the configuration\nRepository updates is listed more than once in the configuration\nRepository extras is listed more than once in the configuration\nRepository centosplus is listed more than once in the configuration\nRepository base is listed more than once in the configuration\nRepository updates is listed more than once in the configuration\nRepository extras is listed more than once in the configuration\nRepository centosplus is listed more than once in the configuration\nRepository epel is listed more than once in the configuration\nRepository epel-debuginfo is listed more than once in the configuration\nRepository epel-source is listed more than once in the configuration\nhttps://mirrors.aliyun.com/centos/7.4.1708/virt/x86_64/kubernetes19/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found\nTrying other mirror.\nTo address this issue please refer to the below knowledge base article \n\nhttps://access.redhat.com/articles/1320623\n\nIf above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/\n\n", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * epel: mirrors.aliyun.com\nResolving Dependencies\n--> Running transaction check\n---> Package curl.x86_64 0:7.29.0-42.el7 will be updated\n---> Package curl.x86_64 0:7.29.0-46.el7 will be an update\n--> Processing Dependency: libcurl = 7.29.0-46.el7 for package: curl-7.29.0-46.el7.x86_64\n--> Running transaction check\n---> Package libcurl.x86_64 0:7.29.0-42.el7 will be updated\n---> Package libcurl.x86_64 0:7.29.0-46.el7 will be an update\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package          Arch            Version                   Repository     Size\n================================================================================\nUpdating:\n curl             x86_64          7.29.0-46.el7             base          268 k\nUpdating for dependencies:\n libcurl          x86_64          7.29.0-46.el7             base          220 k\n\nTransaction Summary\n================================================================================\nUpgrade  1 Package (+1 Dependent package)\n\nTotal download size: 488 k\nDownloading packages:\nDelta RPMs disabled because /usr/bin/applydeltarpm not installed.\n--------------------------------------------------------------------------------\nTotal                                              960 kB/s | 488 kB  00:00     \nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Updating   : libcurl-7.29.0-46.el7.x86_64                                 1/4 \n  Updating   : curl-7.29.0-46.el7.x86_64                                    2/4 \n  Cleanup    : curl-7.29.0-42.el7.x86_64                                    3/4 \n  Cleanup    : libcurl-7.29.0-42.el7.x86_64                                 4/4 \n  Verifying  : curl-7.29.0-46.el7.x86_64                                    1/4 \n  Verifying  : libcurl-7.29.0-46.el7.x86_64                                 2/4 \n  Verifying  : libcurl-7.29.0-42.el7.x86_64                                 3/4 \n  Verifying  : curl-7.29.0-42.el7.x86_64                                    4/4 \n\nUpdated:\n  curl.x86_64 0:7.29.0-46.el7                                                   \n\nDependency Updated:\n  libcurl.x86_64 0:7.29.0-46.el7                                                \n\nComplete!\n"
    ]
}
[[email protected] ~]# ansible Client -m yum -a "name=curl state=latest"
192.168.91.130 | SUCCESS => {
    "changed": false, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "All packages providing curl are up to date", 
        ""
    ]
}

從 msg 和 results 輸出的資訊可以看到,這就是一個 yum 安裝軟體包的過程。

cron 模組

cron 模組用於配置遠端主機 crontab
例如:

ansible Client -m cron -a "name='check' minute='1' job='ntpdate asia.pool.ntp.org'"

執行效果:

[root@xdhuxc ~]# ansible Client -m cron -a "name='check' minute='1' job='ntpdate asia.pool.ntp.org'"
192.168.91.130 | SUCCESS => {
    "changed": true, 
    "envs": [], 
    "jobs": [
        "check"
    ]
}
[root@xdhuxc ~]# ansible Client -m command -a "crontab -l"
192.168.91.130 | SUCCESS | rc=0 >>
#Ansible: check
1 * * * * ntpdate asia.pool.ntp.org

[root@xdhuxc ~]# 
service 模組

service 模組可以用來管理遠端主機的系統服務。
例如:

ansible Client -m service -a "name=haproxy state=stopped"
ansible Client -m service -a "name=haproxy state=restarted"
ansible Client -m service -a "name=haproxy state=reloaded"

命令執行的結果為:

[[email protected] ~]# systemctl status haproxy
● haproxy.service - HAProxy Load Balancer
   Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2018-06-11 23:17:21 CST; 2s ago
 Main PID: 2135 (haproxy-systemd)
   Memory: 1.9M
   CGroup: /system.slice/haproxy.service
           ├─2135 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
           ├─2136 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
           └─2137 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds

Jun 11 23:17:21 xdhuxc systemd[1]: Started HAProxy Load Balancer.
Jun 11 23:17:21 xdhuxc systemd[1]: Starting HAProxy Load Balancer...
Jun 11 23:17:21 xdhuxc haproxy-systemd-wrapper[2135]: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
[[email protected] ~]# ansible Client -m service -a "name=haproxy state=stopped"
192.168.91.128 | SUCCESS => {
    "changed": true, 
    "name": "haproxy", 
    "state": "stopped", 
    "status": {
        "ActiveEnterTimestamp": "Mon 2018-06-11 23:17:21 CST", 
        "ActiveEnterTimestampMonotonic": "4444399885", 
        "ActiveExitTimestampMonotonic": "0", 
        "ActiveState": "active", 
        "After": "basic.target system.slice network.target systemd-journald.socket syslog.target", 
        "AllowIsolate": "no", 
        "AmbientCapabilities": "0", 
        "AssertResult": "yes", 
        "AssertTimestamp": "Mon 2018-06-11 23:17:21 CST", 
        "AssertTimestampMonotonic": "4444398724", 
        "Before": "shutdown.target", 
        "BlockIOAccounting": "no", 
        "BlockIOWeight": "18446744073709551615", 
        "CPUAccounting": "no", 
        "CPUQuotaPerSecUSec": "infinity", 
        "CPUSchedulingPolicy": "0", 
        "CPUSchedulingPriority": "0", 
        "CPUSchedulingResetOnFork": "no", 
        "CPUShares": "18446744073709551615", 
        "CanIsolate": "no", 
        "CanReload": "yes", 
        "CanStart": "yes", 
        "CanStop": "yes", 
        "CapabilityBoundingSet": "18446744073709551615", 
        "ConditionResult": "yes", 
        "ConditionTimestamp": "Mon 2018-06-11 23:17:21 CST", 
        "ConditionTimestampMonotonic": "4444398724", 
        "Conflicts": "shutdown.target", 
        "ControlGroup": "/system.slice/haproxy.service", 
        "ControlPID": "0", 
        "DefaultDependencies": "yes", 
        "Delegate": "no", 
        "Description": "HAProxy Load Balancer", 
        "DevicePolicy": "auto", 
        "EnvironmentFile": "/etc/sysconfig/haproxy (ignore_errors=no)", 
        "ExecMainCode": "0", 
        "ExecMainExitTimestampMonotonic": "0", 
        "ExecMainPID": "2135", 
        "ExecMainStartTimestamp": "Mon 2018-06-11 23:17:21 CST", 
        "ExecMainStartTimestampMonotonic": "4444399843", 
        "ExecMainStatus": "0", 
        "ExecReload": "{ path=/bin/kill ; argv[]=/bin/kill -USR2 $MAINPID ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
        "ExecStart": "{ path=/usr/sbin/haproxy-systemd-wrapper ; argv[]=/usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid $OPTIONS ; ignore_errors=no ; start_time=[Mon 2018-06-11 23:17:21 CST] ; stop_time=[n/a] ; pid=2135 ; code=(null) ; status=0/0 }", 
        "FailureAction": "none", 
        "FileDescriptorStoreMax": "0", 
        "FragmentPath": "/usr/lib/systemd/system/haproxy.service", 
        "GuessMainPID": "yes", 
        "IOScheduling": "0", 
        "Id": "haproxy.service", 
        "IgnoreOnIsolate": "no", 
        "IgnoreOnSnapshot": "no", 
        "IgnoreSIGPIPE": "yes", 
        "InactiveEnterTimestampMonotonic": "0", 
        "InactiveExitTimestamp": "Mon 2018-06-11 23:17:21 CST", 
        "InactiveExitTimestampMonotonic": "4444399885", 
        "JobTimeoutAction": "none", 
        "JobTimeoutUSec": "0", 
        "KillMode": "mixed", 
        "KillSignal": "15", 
        "LimitAS": "18446744073709551615", 
        "LimitCORE": "18446744073709551615", 
        "LimitCPU": "18446744073709551615", 
        "LimitDATA": "18446744073709551615", 
        "LimitFSIZE": "18446744073709551615", 
        "LimitLOCKS": "18446744073709551615", 
        "LimitMEMLOCK": "65536", 
        "LimitMSGQUEUE": "819200", 
        "LimitNICE": "0", 
        "LimitNOFILE": "4096", 
        "LimitNPROC": "3818", 
        "LimitRSS": "18446744073709551615", 
        "LimitRTPRIO": "0", 
        "LimitRTTIME": "18446744073709551615", 
        "LimitSIGPENDING": "3818", 
        "LimitSTACK": "18446744073709551615", 
        "LoadState": "loaded", 
        "MainPID": "2135", 
        "MemoryAccounting": "no", 
        "MemoryCurrent": "2060288", 
        "MemoryLimit": "18446744073709551615", 
        "MountFlags": "0", 
        "Names": "haproxy.service", 
        "NeedDaemonReload": "no", 
        "Nice": "0", 
        "NoNewPrivileges": "no", 
        "NonBlocking": "no", 
        "NotifyAccess": "none", 
        "OOMScoreAdjust": "0", 
        "OnFailureJobMode": "replace", 
        "PermissionsStartOnly": "no", 
        "PrivateDevices": "no", 
        "PrivateNetwork": "no", 
        "PrivateTmp": "no", 
        "ProtectHome": "no", 
        "ProtectSystem": "no", 
        "RefuseManualStart": "no", 
        "RefuseManualStop": "no", 
        "RemainAfterExit": "no", 
        "Requires": "basic.target", 
        "Restart": "no", 
        "RestartUSec": "100ms", 
        "Result": "success", 
        "RootDirectoryStartOnly": "no", 
        "RuntimeDirectoryMode": "0755", 
        "SameProcessGroup": "no", 
        "SecureBits": "0", 
        "SendSIGHUP": "no", 
        "SendSIGKILL": "yes", 
        "Slice": "system.slice", 
        "StandardError": "inherit", 
        "StandardInput": "null", 
        "StandardOutput": "journal", 
        "StartLimitAction": "none", 
        "StartLimitBurst": "5", 
        "StartLimitInterval": "10000000", 
        "StartupBlockIOWeight": "18446744073709551615", 
        "StartupCPUShares": "18446744073709551615", 
        "StatusErrno": "0", 
        "StopWhenUnneeded": "no", 
        "SubState": "running", 
        "SyslogLevelPrefix": "yes", 
        "SyslogPriority": "30", 
        "SystemCallErrorNumber": "0", 
        "TTYReset": "no", 
        "TTYVHangup": "no", 
        "TTYVTDisallocate": "no", 
        "TasksAccounting": "no", 
        "TasksCurrent": "18446744073709551615", 
        "TasksMax": "18446744073709551615", 
        "TimeoutStartUSec": "1min 30s", 
        "TimeoutStopUSec": "1min 30s", 
        "TimerSlackNSec": "50000", 
        "Transient": "no", 
        "Type": "simple", 
        "UMask": "0022", 
        "UnitFilePreset": "disabled", 
        "UnitFileState": "disabled", 
        "Wants": "system.slice", 
        "WatchdogTimestamp": "Mon 2018-06-11 23:17:21 CST", 
        "WatchdogTimestampMonotonic": "4444399872", 
        "WatchdogUSec": "0"
    }
}
[[email protected] ~]# systemctl status haproxy
● haproxy.service - HAProxy Load Balancer
   Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

Jun 11 23:17:21 xdhuxc systemd[1]: Started HAProxy Load Balancer.
Jun 11 23:17:21 xdhuxc systemd[1]: Starting HAProxy Load Balancer...
Jun 11 23:17:21 xdhuxc haproxy-systemd-wrapper[2135]: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
Jun 11 23:17:51 xdhuxc systemd[1]: Stopping HAProxy Load Balancer...
Jun 11 23:17:51 xdhuxc haproxy-systemd-wrapper[2135]: haproxy-systemd-wrapper: SIGTERM -> 2137.
Jun 11 23:17:51 xdhuxc systemd[1]: Stopped HAProxy Load Balancer.
Jun 11 23:17:51 xdhuxc haproxy-systemd-wrapper[2135]: haproxy-systemd-wrapper: exit, haproxy RC=0
[[email protected] ~]# ansible Client -m service -a "name=haproxy state=restarted"
192.168.91.128 | SUCCESS => {
    "changed": true, 
    "name": "haproxy", 
    "state": "started", 
    "status": {
        "ActiveEnterTimestampMonotonic": "0", 
        "ActiveExitTimestampMonotonic": "0", 
        "ActiveState": "inactive", 
        "After": "network.target syslog.target systemd-journald.socket basic.target system.slice", 
        "AllowIsolate": "no", 
        "AmbientCapabilities": "0", 
        "AssertResult": "no", 
        "AssertTimestampMonotonic": "0", 
        "Before": "shutdown.target", 
        "BlockIOAccounting": "no", 
        "BlockIOWeight": "18446744073709551615", 
        "CPUAccounting": "no", 
        "CPUQuotaPerSecUSec": "infinity", 
        "CPUSchedulingPolicy": "0", 
        "CPUSchedulingPriority": "0", 
        "CPUSchedulingResetOnFork": "no", 
        "CPUShares": "18446744073709551615", 
        "CanIsolate": "no", 
        "CanReload": "yes", 
        "CanStart": "yes", 
        "CanStop": "yes", 
        "CapabilityBoundingSet": "18446744073709551615", 
        "ConditionResult": "no", 
        "ConditionTimestampMonotonic": "0", 
        "Conflicts": "shutdown.target", 
        "ControlPID": "0", 
        "DefaultDependencies": "yes", 
        "Delegate": "no", 
        "Description": "HAProxy Load Balancer", 
        "DevicePolicy": "auto", 
        "EnvironmentFile": "/etc/sysconfig/haproxy (ignore_errors=no)", 
        "ExecMainCode": "0", 
        "ExecMainExitTimestampMonotonic": "0", 
        "ExecMainPID": "0", 
        "ExecMainStartTimestampMonotonic": "0", 
        "ExecMainStatus": "0", 
        "ExecReload": "{ path=/bin/kill ; argv[]=/bin/kill -USR2 $MAINPID ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
        "ExecStart": "{ path=/usr/sbin/haproxy-systemd-wrapper ; argv[]=/usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid $OPTIONS ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
        "FailureAction": "none", 
        "FileDescriptorStoreMax": "0", 
        "FragmentPath": "/usr/lib/systemd/system/haproxy.service", 
        "GuessMainPID": "yes", 
        "IOScheduling": "0", 
        "Id": "haproxy.service", 
        "IgnoreOnIsolate": "no", 
        "IgnoreOnSnapshot": "no", 
        "IgnoreSIGPIPE": "yes", 
        "InactiveEnterTimestampMonotonic": "0", 
        "InactiveExitTimestampMonotonic": "0", 
        "JobTimeoutAction": "none", 
        "JobTimeoutUSec": "0", 
        "KillMode": "mixed", 
        "KillSignal": "15", 
        "LimitAS": "18446744073709551615", 
        "LimitCORE": "18446744073709551615", 
        "LimitCPU": "18446744073709551615", 
        "LimitDATA": "18446744073709551615", 
        "LimitFSIZE": "18446744073709551615", 
        "LimitLOCKS": "18446744073709551615", 
        "LimitMEMLOCK": "65536", 
        "LimitMSGQUEUE": "819200", 
        "LimitNICE": "0", 
        "LimitNOFILE": "4096", 
        "LimitNPROC": "3818", 
        "LimitRSS": "18446744073709551615", 
        "LimitRTPRIO": "0", 
        "LimitRTTIME": "18446744073709551615", 
        "LimitSIGPENDING": "3818", 
        "LimitSTACK": "18446744073709551615", 
        "LoadState": "loaded", 
        "MainPID": "0", 
        "MemoryAccounting": "no", 
        "MemoryCurrent": "18446744073709551615", 
        "MemoryLimit": "18446744073709551615", 
        "MountFlags": "0", 
        "Names": "haproxy.service", 
        "NeedDaemonReload": "no", 
        "Nice": "0", 
        "NoNewPrivileges": "no", 
        "NonBlocking": "no", 
        "NotifyAccess": "none", 
        "OOMScoreAdjust": "0", 
        "OnFailureJobMode": "replace", 
        "PermissionsStartOnly": 
            
           

相關推薦

Ansible 學習常用模組

模組相關命令 (1)列出 ansible 支援的模組 ansible-doc -l (2)檢視該模組的幫助資訊 ansible-doc ping # 檢視 ping 模組的幫助資訊 以下實驗均是在 IP 地址為: 192.168.91.128

python學習-常用模組

json 和pickle 模組 json和pickle模組下都有4個功能 dumps  <---> loads  (序列化 <--->反序列化) dump <---> load (簡單寫法序列化<---> 簡單寫法反序列化) 用途:序

Ansible學習01-常用模組

1.command命令模組 預設模組 [email protected]:/data/sh# ansible docker -a "hostname" 192.168.1.124 | success | rc=0 >> centos-my

Ansible學習】- 常用檔案操作模組copy模組

簡介 copy模組用於將本地或遠端機器上的檔案拷貝到遠端主機上。 模組引數 名稱 必選 預設值 可選值 備註 backup no no

Python學習【第9篇】:Python常用模組二(時間模組,序列化模組等) 常用模組2

常用模組2 一、time模組 表示時間的三種方式:   時間戳:數字(計算機能認識的)   時間字串:t='2012-12-12'

Python學習【第8篇】:Python常用模組一(主要是正則以及collections模組) python--------------常用模組正則

python--------------常用模組之正則 一、認識模組     什麼是模組:一個模組就是一個包含了python定義和宣告的檔案,檔名就是加上.py的字尾,但其實import載入的模組分為四個通用類別 :

Python 常用模組學習

模組介紹 time &datetime模組 random os sys shutil json & picle shelve xml處理 yaml處理 configparser hashlib subprocess logging模組 re正則表示式 檢視:https://w

Python的學習旅———模組與包的使用 常用模組

一:import 匯入模組,只會在第一次匯入時執行原始檔的程式碼 如果模組已經載入到記憶體了,下一次匯入直接引用記憶體中匯入的結果 eval:提取字串內的表示式執行,然後返回執行結果 import 匯入檔案都做了哪些事? 1 以原始檔為準產生一個名稱空間2 以剛剛產生

自動化運維Ansible常用模組

[TOC] # 0、Ansible模組語法 在ansible中是指需要快速執行一條命令,並且不需要儲存的命令,對於複雜的命令則為playbook 檢視模組幫助:ansible-doc -l ```bash // 統計模組數量 $ ansible-doc -l |wc -l 3387 // ansi

c++ 學習常用時間函數一覽

差異 進行 學習 當前時間 沒有 使用 ++ 本地 轉換 c++ 學習之常用時間函數一覽 時間的種類 本地時間:UTC + 時區差 = 本地時間 UTC(世界協調時):以地球自轉為基礎的時間標準。 GMT(世界時,格林威治時間):對地球轉速周期性差異進行校正後的世界時。 一

vue學習常用命令

常用命令 posit num 綁定 this scrip efs lazy 性能 一、插值 1.1 +號運用 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U

C++基礎學習程式設計模組(4)

函式和二維陣列 在C++中,二維陣列的定義完全與一維陣列不同: int data[3][4] = {{1, 2, 3, 4}, {9, 8, 7, 6}, {2, 4, 6, 8}}; data不能當作是一維陣列的指標然後去訪問12個元素,data[0~2]每個都是一個一維陣列

機器學習常用矩陣/向量運算

1. Matrix product (矩陣乘法) 定義: 給定 m × p

2018年10月31日Java學習常用的命令列操作

1.常用的命令列操作 win+r調出並輸入cmd. 進入D盤:D:回車進入D盤:D:回車 D盤下的目錄DIR回車 建立目錄md 2018年10月31日 那麼建立了一個2018年10月31日的目錄(目前還在d盤目錄) 進入2018年10月31日的目錄 cd

Kotlin學習常用高階函式:filter

與filter相似的還有以下幾個: filterNot()和filterNotTo():與filter相反,這兩個函式會過濾出不符合條件的元素; filterIndexed()和filterIndexedTo():這兩個函式接受(Int,T)->Boolean型別的函式,同時檢

Linux學習常用命令

須知:常用幫助 man  命令(本機不能執行,莫名其妙)或 命令 --help   ls(list)列出檔案(搭配pwd顯示當前路徑使用更佳) ls 無參 列出當前目錄非隱藏檔案(等同於ls -A) ls 目錄 列出該目錄所有檔案 ls 檔案 無意義,-l 列出檔案詳細資訊

python學習-hashlib模組(加密演算法模組

hash演算法模組內有很多種,如md5、sha1等,只是加密的程度不一樣 hash是一種演算法 該演算法接收傳入的文字內容,經過hash運算得到一串hash值 hash值具備三個特點: 1. 如果傳入的內容相同,得到hash一定相同 2. 不能根據hash值反推出內容(無法反解,但是目前已被破解)

python學習-re模組(正則表示式模組

什麼是正則表示式 正則就是用一些具有特殊含義的符號組合到一起(稱為正則表示式)來描述字元或者字串的方法。或者說:正則就是用來描述一類事物的規則。(在Python中)它內嵌在Python中,並通過 re 模組實現。正則表示式模式被編譯成一系列的位元組碼,然後由用 C 編寫的匹配引擎執行。 生活中處處都是正則

dubbo學習-常用功能

多版本支援 設定不同版本的目的,就是要考慮到介面升級以後帶來的相容問題。 在Dubbo中配置不同版本的介面,會在Zookeeper地址中有多個協議url的體現,具體內容如下 dubbo://192.168.11.1:20880%2Fcom.gupaoedu.dubbo.IGpHello%3F

python學習-subprocess模組(子程序模組

什麼是程序 一個程式執行起來了就是一個程序 但是程式本身不是程序,程式是一對程式碼而已 所以程序就是一個抽象的概念,就是程式執行起來的一個過程 程序和程序之間是相互獨立的,互不影響 如何理解子程序和父程序 抽象的說一個QQ程式是一個父程序,word就是一個子程序,兩個互不干預,當然這只是一個比喻