{"id":7612,"date":"2025-05-07T10:28:39","date_gmt":"2025-05-07T02:28:39","guid":{"rendered":"https:\/\/www.5x44.cn\/?p=7612"},"modified":"2025-05-07T10:28:39","modified_gmt":"2025-05-07T02:28:39","slug":"ansible%e6%9c%ac%e5%9c%b0%e4%bb%a3%e7%90%86%e6%89%a7%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=7612","title":{"rendered":"ansible\u672c\u5730\u4ee3\u7406\u6267\u884c"},"content":{"rendered":"\n<p>\u5728\u9700\u8981\u5411\u8fdc\u7aef\u4e3b\u673a\u4f20\u9001\u6587\u4ef6\uff0c\u4f46\u8fdc\u7aef\u4e3b\u673a\u6ca1\u6709python\u6216\u6ca1\u6709rsync\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u672c\u5730\u4ee3\u7406\u6267\u884c\uff0c\u4f7f\u7528scp\u6765\u4e0a\u4f20\u6587\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>- name: upload file to remote hosts\n  hosts: all\n  gather_facts: no\n  # \u5f53\u8fdc\u7aef\u4e3b\u673a\u6ca1\u6709rsync\u65f6,\u4f7f\u7528scp\u4e0a\u4f20\u6587\u4ef6\n  tasks:\n    - name: \u4e0a\u4f20\u6587\u4ef6\u5939\u6216\u6587\u4ef6\u5230\u670d\u52a1\u5668\n      local_action: |\n        ansible.builtin.command sshpass -p {{ ansible_password }} scp \/mnt\/d\/mjxtPackage\/front-install\/etc_data\/ntpdate-4.2.6p5-29.el7.centos.x86_64.rpm root@{{ ansible_host }}:\/etc_data\/<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u662f\u5728\u672c\u5730\u4ee3\u7406\u7684\u4e00\u4e2a\u5feb\u6377\u65b9\u6cd5\uff0c\u5176\u6b63\u5e38\u6a21\u5f0f\u662f\u4f7f\u7528<em><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">delegate_to<\/mark><\/strong><\/em>\u53c2\u6570\u8bbe\u7f6e\u4ee3\u7406\u6267\u884c\u7684\u673a\u5668\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>- name: upload file to remote hosts\n  hosts: all\n  gather_facts: no\n  # \u5f53\u8fdc\u7aef\u4e3b\u673a\u6ca1\u6709rsync\u65f6,\u4f7f\u7528scp\u4e0a\u4f20\u6587\u4ef6\n  tasks:\n    - name: \u4e0a\u4f20\u6587\u4ef6\u5939\u6216\u6587\u4ef6\u5230\u670d\u52a1\u5668\n      ansible.builtin.command: |\n        ansible.builtin.command sshpass -p {{ ansible_password }} scp \/mnt\/d\/mjxtPackage\/front-install\/etc_data\/ntpdate-4.2.6p5-29.el7.centos.x86_64.rpm root@{{ ansible_host }}:\/etc_data\/\n      delegate_to: 127.0.0.1<\/code><\/pre>\n\n\n\n<p>\u7531\u4e8e\u6211\u662f\u5728inventory\u4e2d\u5b58\u653e\u5bc6\u7801\uff0c\u6240\u4ee5\u5728\u8c03\u7528\u65f6\u4f7f\u7528{{ ansible_password }}\u6765\u8c03\u7528\u5f53\u524d\u88ab\u63a7\u4e3b\u673a\u7684\u5bc6\u7801\uff0c\u7528\u4e8escp\u8fde\u63a5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>all:\n    vars:\n        ansible_ssh_common_args: '-o StrictHostKeyChecking=no'\n        ansible_executable: '\/bin\/bash'\ng00000000000001:\n  hosts:\n    ipc01:\n      ansible_host: 1.2.3.4\n      ansible_user: root\n      ansible_password: xxabc23@cf<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u9700\u8981\u5411\u8fdc\u7aef\u4e3b\u673a\u4f20\u9001\u6587\u4ef6\uff0c\u4f46\u8fdc\u7aef\u4e3b\u673a\u6ca1\u6709python\u6216\u6ca1\u6709rsync\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u672c\u5730\u4ee3\u7406\u6267\u884c\uff0c\u4f7f\u7528scp\u6765\u4e0a\u4f20\u6587\u4ef6\u3002 \u4e0a\u9762\u662f\u5728\u672c\u5730\u4ee3\u7406\u7684\u4e00\u4e2a\u5feb\u6377\u65b9\u6cd5\uff0c\u5176\u6b63\u5e38\u6a21\u5f0f&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=7612\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,15],"tags":[],"class_list":["post-7612","post","type-post","status-publish","format-standard","hentry","category-it","category-python3"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/7612","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7612"}],"version-history":[{"count":2,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/7612\/revisions"}],"predecessor-version":[{"id":7614,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/7612\/revisions\/7614"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}