{"id":229,"date":"2023-08-30T14:46:31","date_gmt":"2023-08-30T06:46:31","guid":{"rendered":"http:\/\/xianyijitan.top\/?p=229"},"modified":"2023-08-30T14:46:31","modified_gmt":"2023-08-30T06:46:31","slug":"ansible-%e4%b8%ad-error-%e5%a4%84%e7%90%86%e6%9c%ba%e5%88%b6","status":"publish","type":"post","link":"https:\/\/xianyijitan.top\/?p=229","title":{"rendered":"Ansible \u4e2d error \u5904\u7406\u673a\u5236"},"content":{"rendered":"<h2>error\u5904\u7406\u673a\u5236\u4ecb\u7ecd<\/h2>\n<p><strong>\u5f53Playbook\u4e2d\u5305\u542b\u5f88\u591a\u4efb\u52a1\u65f6\uff0c\u67d0\u4e00\u4e2a\u4efb\u52a1\u9047\u5230\u9519\u8bef\uff0c\u5b83\u5c06\u5d29\u6e83\uff0c\u7ec8\u6b62\u6267\u884c\u3002\u9ed8\u8ba4Ansible\u5728\u9047\u5230error\u4f1a\u7acb\u523b\u505c\u6b62playbook\u3002<\/strong><\/p>\n<p><strong>\u5728webservers\u7ec4\u4e2d\u7684\u4e3b\u673a\u4e0a\u542f\u52a8mysqld\u670d\u52a1\uff0c\u7136\u540e\u521b\u5efa\/tmp\/service.txt\uff0c\u4ee3\u7801\u793a\u610f\u5982\u4e0b\uff1a<\/strong><\/p>\n<pre><code class=\"language-shell\"># \u7f16\u5199playbook\n[root@pubserver ansible]# vim myer.yml\n---\n- name: my errors\n  hosts: webservers\n  tasks:\n    - name: start mysqld service\n      service:      # \u8c03\u7528\u63d2\u4ef6\u5f00\u59cbmysqld\u670d\u52a1\n        name: mysqld\n        state: started\n        enabled: yes\n\n    - name: touch a file\n      file:\n        path: \/tmp\/services.txt\n        state: touch\n\n[root@pubserver ansible]# ansible-playbook myer.yml \n    .......\nfatal: [web2]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Could not find the requested service mysqld: host&quot;}\nfatal: [web1]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Could not find the requested service mysqld: host&quot;}\n    .......\n<\/code><\/pre>\n<p><strong>\u56e0\u4e3a\u76ee\u6807\u4e3b\u673a\u4e0a\u6ca1\u6709mysqld\u670d\u52a1\uff0c\u6240\u4ee5\u6267\u884cplaybook\u7684\u7b2c1\u4e2a\u4efb\u52a1\u5c31\u4f1a\u5931\u8d25\u3002\u5230node1\u4e0a\u67e5\u770b\uff0c\u56e0\u4e3a\u7b2c2\u4e2a\u4efb\u52a1\u6ca1\u6709\u6267\u884c\uff0c\u6240\u4ee5\u6587\u4ef6\/tmp\/service.txt\u4e0d\u4f1a\u521b\u5efa\uff0c\u4ee3\u7801\u793a\u610f\u5982\u4e0b\uff1a<\/strong><\/p>\n<pre><code class=\"language-shell\">[root@web1 ~]# ls \/tmp\/service.txt\nls: cannot access &#039;\/tmp\/service.txt&#039;: No such file or directory<\/code><\/pre>\n<p><strong>\u91cd\u70b9\uff1a\u53ef\u4ee5\u4f7f\u7528ignore_errors\u53ef\u4ee5\u5ffd\u7565\u9519\u8bef\uff0c\u7ee7\u7eed\u540e\u7eed\u7684\u4efb\u52a1\u3002<\/strong><\/p>\n<h2>\u5c40\u90e8\u8bbe\u7f6e<\/h2>\n<p><strong>\u5c40\u90e8\u8bbe\u7f6e\uff1a\u6307\u5b9a\u67d0\u4e00\u4e2a\u4efb\u52a1\u5982\u679c\u51fa\u73b0\u9519\u8bef\uff0c\u5219\u5ffd\u7565\u5b83\uff08\u5b9a\u4e49\u5728tests\u7ea7\u522b\u5904\uff09\u3002<\/strong><\/p>\n<p><strong>\u5982\u679cmyslqd\u670d\u52a1\u65e0\u6cd5\u542f\u52a8\uff0c\u5219\u5ffd\u7565\u5b83\uff0c\u4ee3\u7801\u793a\u610f\u5982\u4e0b\uff1a<\/strong><\/p>\n<pre><code class=\"language-shell\">[root@pubserver ansible]# vim myer.yml \n---\n- name: my errors\n  hosts: webservers\n  tasks:\n    - name: start mysqld service\n      service:\n        name: mysqld\n        state: started\n        enabled: yes\n      ignore_errors: yes    # \u4efb\u52a1\u5931\u8d25\u4e5f\u4f1a\u7ee7\u7eed\u6267\u884c\u4e0b\u53bb\n\n    - name: touch a file\n      file:\n        path: \/tmp\/services.txt\n        state: touch\n\n[root@pubserver ansible]# ansible-playbook myer.yml \n\nPLAY [my errors] **********************************************************************************************************************************\n\nTASK [Gathering Facts] ****************************************************************************************************************************\nok: [web2]\nok: [web1]\n\nTASK [start mysqld service] ***********************************************************************************************************************\nfatal: [web1]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Could not find the requested service mysqld: host&quot;}\n...ignoring\nfatal: [web2]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Could not find the requested service mysqld: host&quot;}\n...ignoring\n\nTASK [touch a file] *******************************************************************************************************************************\nchanged: [web2]\nchanged: [web1]\n\nPLAY RECAP ****************************************************************************************************************************************\nweb1                       : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=1   \nweb2                       : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=1   \n\n# \u4f7f\u7528ignore_errors\u540e\uff0c\u7b2c\u4e8c\u4e2a\u4efb\u52a1\u6267\u884c\n[root@web1 ~]# ls \/tmp\/services.txt \n\/tmp\/services.txt<\/code><\/pre>\n<h2>\u5168\u5c40\u8bbe\u7f6e<\/h2>\n<p><strong>\u5168\u5c40\u8bbe\u7f6e\uff1a\u65e0\u8bba\u54ea\u4e2a\u4efb\u52a1\u51fa\u73b0\u95ee\u9898\uff0c\u90fd\u8981\u5ffd\u7565\uff08\u5b9a\u4e49\u5728play\u7ea7\u522b\u5904\uff09\u3002<\/strong><\/p>\n<p><strong>\u4ee3\u7801\u793a\u610f\u5982\u4e0b\uff1a<\/strong><\/p>\n<pre><code class=\"language-shell\">[root@pubserver ansible]# vim myer.yml \n---\n- name: my errors\n  hosts: webservers\n  ignore_errors: yes      # \u5728play\u7ea7\u522b\u5b9a\u4e49\uff0c\u5168\u5c40\u8bbe\u7f6e\uff0c\u5bf9\u6240\u6709\u4efb\u52a1\u90fd\u751f\u6548\n  tasks:\n    - name: start mysqld service\n      service:\n        name: mysqld\n        state: started\n        enabled: yes\n#      ignore_errors: yes    # \u4efb\u52a1\u5931\u8d25\u4e5f\u4f1a\u7ee7\u7eed\u6267\u884c\u4e0b\u53bb\n\n    - name: touch a file\n      file:\n        path: \/tmp\/services.txt\n        state: touch\n[root@pubserver ansible]# ansible-playbook myer.yml \n\nPLAY [my errors] **********************************************************************************************************************************\n\nTASK [Gathering Facts] ****************************************************************************************************************************\nok: [web1]\nok: [web2]\n\nTASK [start mysqld service] ***********************************************************************************************************************\nfatal: [web2]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Could not find the requested service mysqld: host&quot;}\n...ignoring\nfatal: [web1]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Could not find the requested service mysqld: host&quot;}\n...ignoring\n\nTASK [touch a file] *******************************************************************************************************************************\nchanged: [web2]\nchanged: [web1]\n\nPLAY RECAP ****************************************************************************************************************************************\nweb1                       : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=1   \nweb2                       : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=1 <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>error\u5904\u7406\u673a\u5236\u4ecb\u7ecd \u5f53Playbook\u4e2d\u5305\u542b\u5f88\u591a\u4efb\u52a1\u65f6\uff0c\u67d0\u4e00\u4e2a\u4efb\u52a1\u9047\u5230\u9519\u8bef\uff0c\u5b83\u5c06\u5d29\u6e83\uff0c\u7ec8\u6b62\u6267\u884c\u3002\u9ed8\u8ba4Ansible\u5728\u9047\u5230error\u4f1a\u7acb\u523b\u505c\u6b62playbook\u3002 \u5728webservers\u7ec4\u4e2d\u7684\u4e3b\u673a\u4e0a\u542f\u52a8mysqld\u670d\u52a1\uff0c\u7136\u540e\u521b\u5efa\/tmp\/service.txt\uff0c\u4ee3\u7801\u793a\u610f\u5982\u4e0b\uff1a # \u7f16\u5199playbook [root@pubserver ansible]# vim myer.yml &#8212; &#8211; name: my errors hosts: webservers tasks: &#8211; name: start mysqld service service: # \u8c03\u7528\u63d2\u4ef6\u5f00\u59cbmysqld\u670d\u52a1 name: mysqld state: started enabled: yes &#8211; name: touch a file file: path: \/tmp\/services.txt state: touch [root@pubserver ansible]# ansible-playbook myer.yml &#8230;&#8230;. fatal: [web2]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Could not find the requested service mysqld: host&quot;} fatal: [web1]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Could not find the requested service mysqld: host&quot;} &#8230;&#8230;. \u56e0\u4e3a\u76ee\u6807\u4e3b\u673a\u4e0a\u6ca1\u6709mysqld\u670d\u52a1\uff0c\u6240\u4ee5\u6267\u884cplaybook\u7684\u7b2c1\u4e2a\u4efb\u52a1\u5c31\u4f1a\u5931\u8d25\u3002\u5230node1\u4e0a\u67e5\u770b\uff0c\u56e0\u4e3a\u7b2c2\u4e2a\u4efb\u52a1\u6ca1\u6709\u6267\u884c\uff0c\u6240\u4ee5\u6587\u4ef6\/tmp\/service.txt\u4e0d\u4f1a\u521b\u5efa\uff0c\u4ee3\u7801\u793a\u610f\u5982\u4e0b\uff1a [root@web1 ~]# ls \/tmp\/service.txt ls: cannot access &#039;\/tmp\/service.txt&#039;: No such file or directory \u91cd\u70b9\uff1a\u53ef\u4ee5\u4f7f\u7528ignore_errors\u53ef\u4ee5\u5ffd\u7565\u9519\u8bef\uff0c\u7ee7\u7eed\u540e\u7eed\u7684\u4efb\u52a1\u3002 \u5c40\u90e8\u8bbe\u7f6e \u5c40\u90e8\u8bbe\u7f6e\uff1a\u6307\u5b9a\u67d0\u4e00\u4e2a\u4efb\u52a1\u5982\u679c\u51fa\u73b0\u9519\u8bef\uff0c\u5219\u5ffd\u7565\u5b83\uff08\u5b9a\u4e49\u5728tests\u7ea7\u522b\u5904\uff09\u3002 \u5982\u679cmyslqd\u670d\u52a1\u65e0\u6cd5\u542f\u52a8\uff0c\u5219\u5ffd\u7565\u5b83\uff0c\u4ee3\u7801\u793a\u610f\u5982\u4e0b\uff1a [root@pubserver ansible]# vim myer.yml &#8212; &#8211; name: my errors hosts: webservers tasks: &#8211; name: start mysqld service service: name: mysqld state: started enabled: yes ignore_errors: yes # \u4efb\u52a1\u5931\u8d25\u4e5f\u4f1a\u7ee7\u7eed\u6267\u884c\u4e0b\u53bb &#8211; name: touch a file file: path: \/tmp\/services.txt state: touch [root@pubserver ansible]# ansible-playbook myer.yml PLAY [my errors] ********************************************************************************************************************************** TASK [Gathering Facts] **************************************************************************************************************************** ok: [web2] ok: [web1] TASK [start mysqld service] *********************************************************************************************************************** fatal: [web1]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Could not find the requested service mysqld: host&quot;} &#8230;ignoring fatal: [web2]: &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[],"class_list":["post-229","post","type-post","status-publish","format-standard","hentry","category-lixx"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts\/229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=229"}],"version-history":[{"count":1,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts\/229\/revisions"}],"predecessor-version":[{"id":230,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts\/229\/revisions\/230"}],"wp:attachment":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}