{"id":3192,"date":"2018-03-17T14:58:15","date_gmt":"2018-03-17T06:58:15","guid":{"rendered":"http:\/\/switch.linesno.com\/?p=3192"},"modified":"2018-03-17T14:58:15","modified_gmt":"2018-03-17T06:58:15","slug":"ansible-shell-%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"http:\/\/switch.linesno.com\/?p=3192","title":{"rendered":"Ansible shell \u6a21\u5757"},"content":{"rendered":"<h3 id=\"shell-\u6a21\u5757\">shell \u6a21\u5757<\/h3>\n<p>\u8fd9\u4e2a\u662f\u4e00\u4e2a\u5f88\u795e\u5947\u7684\u6a21\u5757\uff0c\u5b83\u4e5f\u662fansible\u7684\u6838\u5fc3\u6a21\u5757\u4e4b\u4e00\u3002\u5b83\u8ddfcommand\u6a21\u5757\u4e00\u6837\u8d1f\u8d23\u5728\u88abansible\u63a7\u5236\u7684\u8282\u70b9\uff08\u670d\u52a1\u5668\uff09\u6267\u884c\u547d\u4ee4\u884c\u3002\u5b83\u4e0ecommand\u6a21\u5757\u6709\u7740\u76f8\u4f3c\u7684\u5730\u65b9\uff0c\u4e5f\u6709\u4e0d\u540c\u7684\u5730\u65b9\uff0c\u770b\u5b8c\u8fd9\u7bc7\u6587\u7ae0\u5c06\u544a\u8bc9\u4f60\u7b54\u6848\u3002<\/p>\n<h3 id=\"shell\u6a21\u5757\u5e38\u7528\u53c2\u6570\"><a name=\"t2\"><\/a>shell\u6a21\u5757\u5e38\u7528\u53c2\u6570<\/h3>\n<table>\n<thead>\n<tr>\n<th>parameter<\/th>\n<th>required<\/th>\n<th>default<\/th>\n<th>choices<\/th>\n<th>comments<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>chdir<\/td>\n<td>no<\/td>\n<td><\/td>\n<td><\/td>\n<td>\u8ddfcommand\u4e00\u6837\u7684\uff0c\u8fd0\u884cshell\u4e4b\u524dcd\u5230\u67d0\u4e2a\u76ee\u5f55<\/td>\n<\/tr>\n<tr>\n<td>creates<\/td>\n<td>no<\/td>\n<td><\/td>\n<td><\/td>\n<td>\u8ddfcommand\u4e00\u6837\u7684\uff0c\u5982\u679c\u67d0\u4e2a\u6587\u4ef6\u5b58\u5728\u5219\u4e0d\u8fd0\u884cshell<\/td>\n<\/tr>\n<tr>\n<td>removes<\/td>\n<td>no<\/td>\n<td><\/td>\n<td><\/td>\n<td>\u8ddfcommand\u4e00\u6837\u7684\uff0c\u5982\u679c\u67d0\u4e2a\u6587\u4ef6<strong>\u4e0d\u5b58\u5728<\/strong>\u5219<strong>\u4e0d\u8fd0\u884cshell<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 id=\"shell\u6a21\u5757\u6848\u4f8b\"><a name=\"t3\"><\/a>shell\u6a21\u5757\u6848\u4f8b<\/h3>\n<p>\u6848\u4f8b1:<br \/>\n\u8ba9\u6240\u6709\u8282\u70b9\u8fd0\u884csomescript.sh\u5e76\u628alog\u8f93\u51fa\u5230somelog.txt\u3002<\/p>\n<pre class=\"prettyprint\"><code class=\"language-shell hljs lasso has-numbering\">$ ansible <span class=\"hljs-attribute\">-i<\/span> hosts <span class=\"hljs-literal\">all<\/span> <span class=\"hljs-attribute\">-m<\/span> shell <span class=\"hljs-attribute\">-a<\/span> <span class=\"hljs-string\">\"sh somescript.sh &gt;&gt; somelog.txt\"<\/span><\/code><\/pre>\n<p>\u6848\u4f8b2:<br \/>\n\u5148\u8fdb\u5165somedir\/ \uff0c\u518d\u5728somedir\/\u76ee\u5f55\u4e0b\u8ba9\u6240\u6709\u8282\u70b9\u8fd0\u884csomescript.sh\u5e76\u628alog\u8f93\u51fa\u5230somelog.txt\u3002<\/p>\n<pre class=\"prettyprint\"><code class=\"language-shell hljs lasso has-numbering\">$ ansible <span class=\"hljs-attribute\">-i<\/span> hosts <span class=\"hljs-literal\">all<\/span> <span class=\"hljs-attribute\">-m<\/span> shell <span class=\"hljs-attribute\">-a<\/span> <span class=\"hljs-string\">\"somescript.sh &gt;&gt; somelog.txt\"<\/span> chdir<span class=\"hljs-subst\">=<\/span>somedir<span class=\"hljs-subst\">\/<\/span><\/code><\/pre>\n<p>\u6848\u4f8b3:<br \/>\n\u4f53\u9a8cshell\u548ccommand\u7684\u533a\u522b,\u5148cd\u5230\u67d0\u4e2a\u9700\u8981\u7f16\u8bd1\u7684\u76ee\u5f55\uff0c\u6267\u884ccondifgure\u7136\u540e,\u7f16\u8bd1\uff0c\u7136\u540e\u5b89\u88c5\u3002<\/p>\n<pre class=\"prettyprint\"><code class=\"language-shell hljs lasso has-numbering\">$ ansible <span class=\"hljs-attribute\">-i<\/span> hosts <span class=\"hljs-literal\">all<\/span> <span class=\"hljs-attribute\">-m<\/span> shell <span class=\"hljs-attribute\">-a<\/span> <span class=\"hljs-string\">\".\/configure &amp;&amp; make &amp;&amp; make insatll\"<\/span> chdir<span class=\"hljs-subst\">=<\/span>\/xxx\/yyy<span class=\"hljs-subst\">\/<\/span><\/code><\/pre>\n<p>shell\u6a21\u5757\u5982\u4f55\u4f7f\u7528\u4f60\u660e\u767d\u4e86\u4e48\uff1f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>shell \u6a21\u5757 \u8fd9\u4e2a\u662f\u4e00\u4e2a\u5f88\u795e\u5947\u7684\u6a21\u5757\uff0c\u5b83\u4e5f\u662fansible\u7684\u6838\u5fc3\u6a21\u5757\u4e4b\u4e00\u3002\u5b83\u8ddfcommand\u6a21\u5757\u4e00\u6837\u8d1f\u8d23\u5728 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[],"class_list":["post-3192","post","type-post","status-publish","format-standard","hentry","category-server"],"_links":{"self":[{"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/posts\/3192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3192"}],"version-history":[{"count":1,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/posts\/3192\/revisions"}],"predecessor-version":[{"id":3193,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/posts\/3192\/revisions\/3193"}],"wp:attachment":[{"href":"http:\/\/switch.linesno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3192"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}