{"id":36442,"date":"2024-11-26T13:11:50","date_gmt":"2024-11-26T05:11:50","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36442\/"},"modified":"2024-11-26T13:11:50","modified_gmt":"2024-11-26T05:11:50","slug":"ansible%e5%ae%9e%e6%88%98-%e7%a3%81%e7%9b%98%e4%bd%bf%e7%94%a8%e7%8e%87%e7%ad%9b%e9%80%89","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36442\/","title":{"rendered":"ansible\u5b9e\u6218&#8212;\u78c1\u76d8\u4f7f\u7528\u7387\u7b5b\u9009"},"content":{"rendered":"<p>\u5e74\u5e95\u4e86\u867d\u7136\u6709\u5404\u79cd\u544a\u8b66\uff0c\u4e0d\u8fc7\u8fd8\u662f\u9700\u8981\u505a\u4e00\u4e0b\u5168\u7f51\u5de1\u68c0\uff0c\u8fd9\u91cc\u4ee5\u78c1\u76d8\u4f7f\u7528\u7387\u4e3a\u4f8b\u3002\u7531\u4e8e\u76ee\u524d\u5e73\u53f0\u4e0a\u4f7f\u7528\u7684\u662f\u5546\u4e1a\u7248\u7684\u81ea\u52a8\u5316\u5de5\u5177bmc\uff0c\u5176\u5728\u6267\u884c\u5206\u53d1\u90fd\u65b9\u9762\u975e\u5e38\u4e0d\u5b58\uff0c\u4e0d\u8fc7\u5728\u53d6\u503c\u8fd4\u56de\u4e0a\u505a\u7684\u4e0d\u597d\uff0d\uff0d\uff0d\u5f53\u7136\u4e5f\u548c\u5176\u662f\u5546\u4e1a\u5316\u5de5\u5177\u6709\u5173\uff0c\u5f88\u591a\u4e1c\u897f\u4e0d\u5f00\u6e90\uff0c\u7528shell \u7684\u8bed\u6cd5\u6982\u5ff5\u5199nsh\u65f6\u53c8\u6267\u884c\u4e0d\u901a\u8fc7\uff0cnnd\u603b\u662f\u8981\u95ee\u539f\u5382\u652f\u6491 \u3002\u521a\u597d\u5728\u6d4b\u8bd5\u73af\u5883\u4e0a\u6709\u4e4b\u524d\u5b89\u88c5\u7684ansible\u73af\u5883\uff0c\u4e5f\u6d4b\u8bd5\u4e0b\u7528ansible \u6765\u5b9e\u73b0\u8be5\u529f\u80fd\u3002<\/p>\n<p><strong>\u4e00\u3001\u5b9e\u73b0\u76ee\u6807<\/strong>  <\/p>\n<p>\u5c06\u6240\u6709\u4e3b\u673a\u7684\u78c1\u76d8\u5927\u4e8e75%\u7684\u4e3b\u673a\u83b7\u53d6\u5230\uff0c\u5e76\u8f93\u51fa\u4e3a\u4e0b\u9762\u7684\u683c\u5f0f\uff1a<\/p>\n<p><span>\u4e3b\u673a<\/span><span>IP <\/span><span>\u4e3b\u673a\u540d<\/span> <span>\u78c1\u76d8\u6302\u8f7d\u70b9\u4fe1\u606f<\/span> <span>\u78c1\u76d8\u4f7f\u7528\u7387<\/span><\/p>\n<p>\u5047\u5982 host1\u4e0a\u6709\u591a\u4e2a\u5206\u533a\u90fd\u5927\u4e8e75% \uff0c\u5219\u5199\u591a\u6761\u3002\u5f53\u4e3b\u673a\u4e0a\u6ca1\u6709\u4e00\u53f0\u7b26\u5408\u65f6\uff0c\u5219\u4ec0\u4e48\u90fd\u4e0d\u8f93\u51fa\u3002<\/p>\n<p>\u6ce8\uff1a\u73b0\u7f51\u4e3b\u673a\u4e0a\u6709\u4e24\u4e2a bond \u7f51\u5361\uff0c\u5176\u4e2d\u4e00\u4e2a\u914d\u7f6e\u7684\u662f10\u6bb5\u7684IP\uff0c\u53e6\u4e00\u4e2a\u914d\u7f6e\u7684\u662f192\u6bb5\u7684IP\u3002\u8fd9\u91cc\u8981\u83b7\u53d6\u7684\u662f10\u6bb5\u7684IP\u3002<\/p>\n<p><strong>\u4e8c\u3001 ansible + awk \u7b80\u5355\u8f93\u51fa<\/strong>  <\/p>\n<p>\u8be5\u95ee\u9898\u6211\u5904\u7406\u7684\u7ed3\u679c\u662f\u4f7f\u7528ansible api \u5199\u7684\u4e00\u4e2apython\u811a\u672c\u5b9e\u73b0\u7684\u3002\u5148\u770b\u4e0b\u6211\u5728\u4e00\u4e2a\u6280\u672f\u7fa4\u548c\u4e00\u4e2a\u5927\u725b\u7684\u8ba8\u8bba\u7684\u7ed3\u679c\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/465\/014\/172683128257319.jpg\" class=\"aligncenter\" title=\"ansible\u5b9e\u6218&#8212;\u78c1\u76d8\u4f7f\u7528\u7387\u7b5b\u9009\u63d2\u56fe\" alt=\"ansible\u5b9e\u6218&#8212;\u78c1\u76d8\u4f7f\u7528\u7387\u7b5b\u9009\u63d2\u56fe\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u5982\u4e0a\u56fe\uff0c\u5927\u725b\u7684\u505a\u6cd5\u7528\u7684\u662fawk \u7684next\u65b9\u6cd5\u8fdb\u884c\u7684\u5904\u7406\uff0cawk \u7684next\u529f\u80fd\u6211\u4e5f\u505a\u8fc7\u8bb0\u5f55\uff0c\u5177\u4f53\u53c2\u770bawk next\u591a\u884c\u5408\u5e76 \u3002<\/p>\n<p>\u8fd9\u91cc\u6709\u51e0\u4e2a\u6ce8\u610f\u70b9\u9700\u8981\u8bf4\u660e\u4e0b\uff1a<\/p>\n<p><span style=\"color: #1e1e1e;letter-spacing: 2px;border-left: #FF3030 3px solid;border-right: #FF3030 3px solid;padding-left: 8px;padding-right: 8px;font-size: 12pt\"><strong>1\u3001\u5927\u725b\u7684\u5199\u6cd5\u4e2d\u5728\u7b5b\u9009\u4e0a\u5199\u7684\u4e0d\u4e25\u8c28\uff0c$5\u524d\u5e94\u8be5\u6709int\u8f6c\u5316\uff0c\u4e0d\u8fc7\u4e0d\u80fd\u6b63\u786e\u7684\u53d6\u5230\u503c<\/strong><\/span>   <\/p>\n<pre>[root@361way ~]# df -hP|awk 'NR&gt;1 &amp;&amp; $5 &gt; 20'\n\/dev\/xvda1 20G 4.6G 15G 25% \/\n\/dev\/xvdb 20G 645M 18G 4% \/data1\n[root@361way ~]# df -hP|awk 'NR&gt;1 &amp;&amp; int($5) &gt; 20'\n\/dev\/xvda1 20G 4.6G 15G 25% \/\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6709\u6ca1\u6709\u770b\u5230\uff0c\u5982\u679c\u4e0d\u505aint\u683c\u5f0f\u8f6c\u6362\u53d6\u7684\u7ed3\u679c\u662f\u6240\u6709\u5206\u533a\u7684\u4fe1\u606f\uff0c\u800c\u52a0\u4e0aint\u540e\u83b7\u53d6\u7684\u624d\u662f\u6211\u4eec\u60f3\u8981\u7684\u7ed3\u679c<\/p>\n<p><span style=\"color: #1e1e1e;letter-spacing: 2px;border-left: #FF3030 3px solid;border-right: #FF3030 3px solid;padding-left: 8px;padding-right: 8px;font-size: 12pt\"><strong>2\u3001\u5728ansible\u6267\u884c\u65f6$5\u524d\u9762\u8981\u52a0\u4e0a\u8f6c\u4e49<\/strong><\/span>   <\/p>\n<pre># ansible all -m shell -a \"df -hP|awk 'NR&gt;1 &amp;&amp; int($5) &gt; 50'\"\n10.212.52.252 | FAILED | rc=2 &gt;&gt;\nawk: fatal: 0 is invalid as number of arguments for int\n[root@361way ~]# df -hP|awk 'NR&gt;1 &amp;&amp; int($5) &gt; 20'\nawk: NR&gt;1 &amp;&amp; int($5) &gt; 20\nawk: ^ backslash not last character on line\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5982\u4e0a\u9762\u7684\u7ed3\u679c\uff0c\u5982\u679c\u5728ansible\u6267\u884c\u65f6\u4e0d\u52a0\u8f6c\u4e49\u65f6\u4f1a\u6709\u62a5\u9519\u63d0\u793a\uff0c\u5982\u679c\u52a0\u4e0a\u8f6c\u4e49\u5728\u4e3b\u673a\u7aef\u6267\u884c\u65f6\u4f1a\u81ea\u52a8\u662f\u5c06\u8f6c\u4e49\u7b26\u53bb\u6389\u7684\u7ed3\u679c\u3002\u800c\u5728\u4e3b\u673a\u7aef\u6267\u884c\u65f6\uff0c\u5982\u679c\u52a0\u4e0a\u4e86\u8f6c\u4e49\u4e5f\u4f1a\u62a5\u9519\u3002\u6240\u4ee5\u4e3b\u673a\u7aef\u4e00\u5b9a\u4e0d\u80fd\u52a0\u4e0a\u8f6c\u4e49\u3002<\/p>\n<p><span style=\"color: #1e1e1e;letter-spacing: 2px;border-left: #FF3030 3px solid;border-right: #FF3030 3px solid;padding-left: 8px;padding-right: 8px;font-size: 12pt\"><strong><\/strong><strong>3\u3001\u5728\u5b9e\u9645\u5e94\u7528\u65f6\uff0c\u8f93\u51fa\u7ed3\u679c\u53ef\u80fd\u548c\u5927\u725b\u7684\u8f93\u51fa\u6709\u5dee\u8ddd<\/strong><\/span>   <\/p>\n<pre>[root@localhost ~]# ansible all -m shell -a \"df -hP|awk 'NR&gt;1 &amp;&amp; int($5) &gt; 30'\"|awk '\/success\/{ip=$1;next}{print ip,$0}'\n10.212.52.252 \/dev\/sda9 9.9G 2.9G 6.5G 31% \/opt\n10.212.52.252 \/dev\/sda6 5.0G 1.9G 2.8G 41% \/tmp\n10.212.52.252 \/dev\/sda5 9.9G 3.9G 5.5G 42% \/usr\n10.212.52.252\n10.212.52.14 \/dev\/cciss\/c0d0p5 9.9G 3.2G 6.3G 34% \/usr\n10.212.52.14\n10.212.52.16 \/dev\/cciss\/c0d0p7 9.9G 4.0G 5.4G 43% \/tmp\n10.212.52.16 \/dev\/cciss\/c0d0p5 9.9G 2.9G 6.5G 31% \/usrdf: `\/root\/.gvfs': Permission denied\n10.212.52.16\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e0a\u9762\u7684\u7ed3\u679c\u662f\u6211\u5728\u81ea\u5df1\u7684\u6d4b\u8bd5\u73af\u5883\u4e0a\u6267\u884c\u7684\u7ed3\u679c\u3002\u53ef\u4ee5\u770b\u5230\u591a\u51fa\u7684\u7a7a\u884c\u4e5f\u6253\u5370\u4e86\u4e3b\u673a\u7684IP \u3002\u8fd8\u4f1a\u9700\u8981\u6ce8\u610f\u7684\uff0c\u6211\u8fd9\u91ccansible\u8f93\u51fa\u7684success\u662f\u5c0f\u5199\u7684\u3002<\/p>\n<p>\u4e0d\u77e5\u9053\u4ee5\u4e0a\u7684\u95ee\u9898\u662f\u4e0d\u662f\u4f7f\u7528\u7684\u73af\u5883\u4e0d\u540c\u9020\u6210\u7684\u3002\u6211\u8fd0\u884c\u7684\u73af\u5883\u662fansible\u4e3b\u673a\u4e3aredhat6\uff0cansible\u7248\u672c\u4e3a1.9\uff0c\u88ab\u53d6\u6570\u636e\u4e3b\u673a\u6709redhat6\u548csuse11 \u3002\u4e0d\u8fc7\u8fd9\u90fd\u662f\u5c0f\u95ee\u9898\uff0c\u540c\u6837\u53ef\u4ee5\u901a\u8fc7\u5904\u7406\u83b7\u53d6\u5230\u6b63\u5e38\u7684\u7ed3\u679c\u3002<\/p>\n<p><span style=\"color: #1e1e1e;letter-spacing: 2px;border-left: #FF3030 3px solid;border-right: #FF3030 3px solid;padding-left: 8px;padding-right: 8px;font-size: 12pt\"><strong>4\u3001ansible api \u6267\u884c<\/strong><\/span>  <\/p>\n<p>\u4e0a\u9762\u7684\u5927\u725b\u7684\u7ed3\u679c\uff0c\u6211\u4f7f\u7528ansible api \u6267\u884c\uff0c\u5982\u4e0b\uff0c\u53ef\u4ee5\u5bf9\u6bd4\u4e0b\uff1a<\/p>\n<pre>[root@localhost ~]# cat \/tmp\/test.py\n#!\/usr\/bin\/env python\n# coding=utf-8\n# author \uff1a www.361way.com\n# mail : itybku@139.com\nimport ansible.runner\n#import json\nrunner = ansible.runner.Runner(\nmodule_name='shell',\nmodule_args=\"df -hP|awk 'NR&gt;1 &amp;&amp; int($5)&gt;30'\",\npattern='all',\nforks=10\n)\nresults = runner.run()\n#print results\nfor (hostname, result) in results['contacted'].items():\nif not 'failed' in result:\nfor line in result['stdout'].split('\n'):\nprint \"%s %s\" % (hostname, line)\n# \u6267\u884c\u7ed3\u679c\u5982\u4e0b\n[root@localhost ~]# python \/tmp\/test.py\n10.212.52.16 \/dev\/cciss\/c0d0p7 9.9G 4.0G 5.4G 43% \/tmp\n10.212.52.16 \/dev\/cciss\/c0d0p5 9.9G 2.9G 6.5G 31% \/usr\n10.212.52.252 \/dev\/sda9 9.9G 2.9G 6.5G 31% \/opt\n10.212.52.252 \/dev\/sda6 5.0G 1.9G 2.8G 41% \/tmp\n10.212.52.252 \/dev\/sda5 9.9G 3.9G 5.5G 42% \/usr\n10.212.52.14 \/dev\/cciss\/c0d0p5 9.9G 3.2G 6.3G 34% \/usr\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236<br \/>\n<strong>\u4e09\u3001\u8fd8\u662fansible api \u83b7\u53d6\u78c1\u76d8\u4fe1\u606f<\/strong>  <\/p>\n<p>\u4e0a\u9762\u7684\u65b9\u6cd5\u4e2d\u5b9e\u9645\u6267\u884c\u65f6\uff0c\u6bd4\u6211\u4eec\u9884\u671f\u9700\u8981\u7684\u6548\u679c\u5c11\u4e86\u4e3b\u673a\u540d\u4e00\u9879\u3002\u8fd9\u91cc\u6211\u6362\u505a\u6267\u884c\u811a\u672c\u5b9e\u73b0\uff0c\u5b9e\u73b0\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<pre>#\/bin\/bash\n# author : www.361way.com\nIP=`ip add show|grep inet|grep 10|awk '{print $2}'`\ndf -hl|grep '^\/'|sed 's\/%\/\/g'|awk '{if($5&gt;30) print $0}'|while read line\ndo\necho $IP `hostname` $line\ndone\n# \u6267\u884c\u7ed3\u679c\u5982\u4e0b\n# sh aa.sh\n10.212.52.253\/24 localhost \/dev\/sda3 9.5G 5.7G 3.4G 64 \/\n10.212.52.253\/24 localhost \/dev\/sda2 39G 19G 18G 52 \/home\n10.212.52.253\/24 localhost \/dev\/sda6 9.5G 7.1G 2.0G 78 \/usr\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4f7f\u7528ansible api \u6267\u884c\u8be5\u811a\u672c\u7684\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<pre># python dfscript.py\ndf: `\/root\/.gvfs': Permission denied\ndf: `\/root\/.gvfs': Permission denied\n10.212.52.16\/24 linux \/dev\/cciss\/c0d0p7 9.9G 4.0G 5.4G 43 \/tmp\n10.212.52.16\/24 linux \/dev\/cciss\/c0d0p5 9.9G 2.9G 6.5G 31 \/usr\n10.212.52.252\/24 zjhz-bmc-test \/dev\/sda9 9.9G 2.9G 6.5G 31 \/opt\n10.212.52.252\/24 zjhz-bmc-test \/dev\/sda6 5.0G 1.9G 2.8G 41 \/tmp\n10.212.52.252\/24 zjhz-bmc-test \/dev\/sda5 9.9G 3.9G 5.5G 42 \/usr\n10.212.52.14\/24 linux \/dev\/cciss\/c0d0p5 9.9G 3.2G 6.3G 34 \/usr\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>dfscript.py\u811a\u672c\u5185\u5bb9\u5982\u4e0b<\/p>\n<pre># cat dfscript.py\n#!\/usr\/bin\/env python\n# coding=utf-8\n# author \uff1a www.361way.com\n# mail : itybku@139.com\nimport ansible.runner\n#import json\nrunner = ansible.runner.Runner(\nmodule_name='script',\nmodule_args=\"aa.sh\",\npattern='all',\nforks=10\n)\nresults = runner.run()\n#print results\nfor (hostname, result) in results['contacted'].items():\nif not 'failed' in result:\nfor line in result['stdout'].split('\r\n'):\n#print \"%s %s\" % (hostname, line)\nprint line\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u76f4\u63a5\u5bf9\u8be5\u811a\u672c\u6267\u884c\u540e\u7684\u7ed3\u679c\u8fdb\u884cgrep \u6807\u51c6\u8f93\u51fa\u65f6\uff0c\u4f1a\u53d1\u73b0\u5176\u884c\u4e0e\u884c\u4e4b\u95f4\u662f\u4ee5 \u8fd9\u6837\u7684\u65b9\u5f0f\u5206\u884c\u7684\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/465\/014\/172683128252251.jpg\" class=\"aligncenter\" title=\"ansible\u5b9e\u6218&#8212;\u78c1\u76d8\u4f7f\u7528\u7387\u7b5b\u9009\u63d2\u56fe1\" alt=\"ansible\u5b9e\u6218&#8212;\u78c1\u76d8\u4f7f\u7528\u7387\u7b5b\u9009\u63d2\u56fe1\" \/><\/p>\n<p>\u6240\u4ee5\u5728\u6570\u636e\u83b7\u53d6\u65b9\u9762\uff0c\u5c3d\u91cf\u4ee5ansible api \u7684\u65b9\u5f0f\u8fdb\u884c\u83b7\u53d6\uff0c\u800capi \u7684\u4f7f\u7528\u975e\u5e38\u7b80\u5355\uff0c\u65e0\u6cd5\u662f\u51e0\u4e2a\u53c2\u6570\u7684\u66ff\u6362\u540e\u9762\u518d\u8c03\u7528run\u65b9\u6cd5\uff0c\u6700\u7ec8\u5728\u5bf9\u7ed3\u679c\u8fdb\u884c\u5904\u7406\u3002\u800c\u6d89\u53ca\u591a\u9879\u4fe1\u606f\u83b7\u53d6\u65f6\uff0c\u5efa\u8bae\u4f7f\u7528\u81ea\u5b9a\u4e49\u6a21\u5757\u7684\u65b9\u6cd5\uff0c\u5148\u5c06\u6240\u9700\u6570\u636e\u53d6\u56de\u6765\uff0c\u4ee5json\u65b9\u5f0f\u8fd4\u56de\uff0d\uff0d\uff0dansible\u81ea\u5b9a\u4e49\u6a21\u5757\u6240\u8981\u6c42\u7684\u683c\u5f0f\u3002\u8fd4\u56de\u540e\u53ef\u4ee5\u518d\u4ee5api \u6216\u5176\u4ed6\u65b9\u5f0f\u5904\u7406\u8fd4\u56de\u7684\u6570\u636e\u5373\u53ef\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fansible\u5b9e\u6218&#8212;\u78c1\u76d8\u4f7f\u7528\u7387\u7b5b\u9009\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e74\u5e95\u4e86\u867d\u7136\u6709\u5404\u79cd\u544a\u8b66\uff0c\u4e0d\u8fc7\u8fd8\u662f\u9700\u8981\u505a\u4e00\u4e0b\u5168\u7f51\u5de1\u68c0\uff0c\u8fd9\u91cc\u4ee5\u78c1\u76d8\u4f7f\u7528\u7387\u4e3a\u4f8b\u3002\u7531\u4e8e\u76ee\u524d\u5e73\u53f0\u4e0a\u4f7f\u7528\u7684\u662f\u5546\u4e1a\u7248\u7684\u81ea\u52a8\u5316\u5de5\u5177bmc\uff0c\u5176\u5728\u6267\u884c\u5206\u53d1\u90fd\u65b9\u9762\u975e\u5e38\u4e0d\u5b58\uff0c\u4e0d\u8fc7\u5728\u53d6\u503c\u8fd4\u56de\u4e0a\u505a\u7684\u4e0d\u597d\uff0d\uff0d\uff0d\u5f53\u7136\u4e5f\u548c\u5176\u662f\u5546\u4e1a\u5316\u5de5\u5177\u6709\u5173\uff0c\u5f88\u591a\u4e1c\u897f\u4e0d\u5f00\u6e90\uff0c\u7528shell \u7684\u8bed\u6cd5\u6982\u5ff5\u5199nsh\u65f6\u53c8\u6267\u884c\u4e0d\u901a\u8fc7\uff0cnnd\u603b\u662f\u8981\u95ee\u539f\u5382\u652f\u6491 \u3002\u521a\u597d\u5728\u6d4b\u8bd5\u73af\u5883\u4e0a\u6709\u4e4b\u524d\u5b89\u88c5\u7684ansible\u73af\u5883\uff0c\u4e5f\u6d4b\u8bd5\u4e0b\u7528ansible \u6765\u5b9e\u73b0\u8be5\u529f\u80fd\u3002 \u4e00\u3001\u5b9e\u73b0\u76ee\u6807 \u5c06\u6240\u6709\u4e3b\u673a\u7684\u78c1\u76d8\u5927\u4e8e75%\u7684\u4e3b\u673a\u83b7\u53d6\u5230\uff0c\u5e76\u8f93\u51fa\u4e3a\u4e0b\u9762\u7684\u683c\u5f0f\uff1a \u4e3b\u673aIP \u4e3b\u673a\u540d \u78c1\u76d8\u6302\u8f7d\u70b9\u4fe1\u606f \u78c1\u76d8\u4f7f\u7528\u7387 \u5047\u5982 host1\u4e0a\u6709\u591a\u4e2a\u5206\u533a\u90fd\u5927\u4e8e75% \uff0c\u5219\u5199\u591a\u6761\u3002\u5f53\u4e3b\u673a\u4e0a\u6ca1\u6709\u4e00\u53f0\u7b26\u5408\u65f6\uff0c\u5219\u4ec0\u4e48\u90fd\u4e0d\u8f93\u51fa\u3002 \u6ce8\uff1a\u73b0\u7f51\u4e3b\u673a\u4e0a\u6709\u4e24\u4e2a bond \u7f51\u5361\uff0c\u5176\u4e2d\u4e00\u4e2a\u914d\u7f6e\u7684\u662f10\u6bb5\u7684IP\uff0c\u53e6\u4e00\u4e2a\u914d\u7f6e\u7684\u662f192\u6bb5\u7684IP\u3002\u8fd9\u91cc\u8981\u83b7\u53d6\u7684\u662f10\u6bb5\u7684IP\u3002 \u4e8c\u3001 ansible + awk \u7b80\u5355\u8f93\u51fa \u8be5\u95ee\u9898\u6211\u5904\u7406\u7684\u7ed3\u679c\u662f\u4f7f\u7528ansible api \u5199\u7684\u4e00\u4e2apython\u811a\u672c\u5b9e\u73b0\u7684\u3002\u5148\u770b\u4e0b\u6211\u5728\u4e00\u4e2a\u6280\u672f\u7fa4\u548c\u4e00\u4e2a\u5927\u725b\u7684\u8ba8\u8bba\u7684\u7ed3\u679c\u3002 &nbsp; \u5982\u4e0a\u56fe\uff0c\u5927\u725b\u7684\u505a\u6cd5\u7528\u7684\u662fawk \u7684next\u65b9\u6cd5\u8fdb\u884c\u7684\u5904\u7406\uff0cawk \u7684next\u529f\u80fd\u6211\u4e5f\u505a\u8fc7\u8bb0\u5f55\uff0c\u5177\u4f53\u53c2\u770bawk next\u591a\u884c\u5408\u5e76 \u3002 \u8fd9\u91cc\u6709\u51e0\u4e2a\u6ce8\u610f\u70b9\u9700\u8981\u8bf4\u660e\u4e0b\uff1a 1\u3001\u5927\u725b\u7684\u5199\u6cd5\u4e2d\u5728\u7b5b\u9009\u4e0a\u5199\u7684\u4e0d\u4e25\u8c28\uff0c$5\u524d\u5e94\u8be5\u6709int\u8f6c\u5316\uff0c\u4e0d\u8fc7\u4e0d\u80fd\u6b63\u786e\u7684\u53d6\u5230\u503c [root@361way ~]# df -hP|awk &#8216;NR&gt;1 &amp;&amp; $5 &gt; 20&#8217; \/dev\/xvda1 20G 4.6G 15G 25% \/ \/dev\/xvdb 20G 645M 18G 4% \/data1 [root@361way ~]# [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-36442","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36442","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=36442"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36442\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}