{"id":103561,"date":"2024-08-30T14:53:12","date_gmt":"2024-08-30T06:53:12","guid":{"rendered":"https:\/\/gulass.cn\/?p=103561"},"modified":"2024-08-30T14:53:12","modified_gmt":"2024-08-30T06:53:12","slug":"ansible-ad-hoc-commands","status":"publish","type":"post","link":"https:\/\/gulass.cn\/ansible-ad-hoc-commands.html","title":{"rendered":"\u4ecb\u7ecdansible\u7684Ad-hoc\u4e0ecommands\u6a21\u5757"},"content":{"rendered":"

Ad-Hoc \u662f\u6307ansible\u4e0b\u4e34\u65f6\u6267\u884c\u7684\u4e00\u6761\u547d\u4ee4\uff0c\u5e76\u4e14\u4e0d\u9700\u8981\u4fdd\u5b58\u7684\u547d\u4ee4\uff0c\u5bf9\u4e8e\u590d\u6742\u7684\u547d\u4ee4\u540e\u9762\u4f1a\u8bf4playbook\u3002\u8bb2\u5230Ad-hoc \u5c31\u8981\u63d0\u5230\u6a21\u5757\uff0c\u6240\u6709\u7684\u547d\u4ee4\u6267\u884c\u90fd\u8981\u4f9d\u8d56\u4e8e\u4e8b\u5148\u5199\u597d\u7684\u6a21\u5757\uff0c\u9ed8\u8ba4\u5b89\u88c5\u597d\u7684ansible \u91cc\u9762\u5df2\u7ecf\u81ea\u5e26\u4e86\u5f88\u591a\u6a21\u5757\uff0c\u5982\uff1acommand\u3001raw\u3001shell\u3001file\u3001cron\u7b49\uff0c\u5177\u4f53\u53ef\u4ee5\u901a\u8fc7ansible-doc -l \u8fdb\u884c\u67e5\u770b \u3002<\/p>\n

\u4e00\u3001Ad-hoc<\/strong><\/div>\n
1\u3001\u76f4\u63a5\u6267\u884c<\/strong><\/span><\/div>\n

\u8fd9\u91cc\u8fd8\u662f\u5148\u6765\u4e00\u4e2a\u4e0a\u51e0\u7bc7\u5e45\u7ecf\u5e38\u7528\u5230\u7684\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n

[root@361way ~]# ansible 10.212.52.252 -a 'uptime' -k\r\nSSH password:\r\n10.212.52.252 | success | rc=0 >>\r\n10:10am up 27 days 19:33, 2 users, load average: 0.39, 0.34, 0.33\r\n<\/pre>\n

\u4e00\u4e2aad-hoc\u547d\u4ee4\u7684\u6267\u884c\uff0c\u9700\u8981\u6309\u4ee5\u4e0b\u683c\u5f0f\u8fdb\u884c\u6267\u884c\uff1a<\/p>\n

    \n
  1. ansible <\/span>\u4e3b\u673a\u6216\u7ec4<\/span> -<\/span>m <\/span>\u6a21\u5757\u540d<\/span> -<\/span>a <\/span>'\u6a21\u5757\u53c2\u6570'<\/span> ansible<\/span>\u53c2\u6570<\/span><\/li>\n<\/ol>\n