{"id":59480,"date":"2026-01-13T23:05:03","date_gmt":"2026-01-13T15:05:03","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/59480.html"},"modified":"2026-01-13T23:05:03","modified_gmt":"2026-01-13T15:05:03","slug":"20260113linux%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/59480.html","title":{"rendered":"20260113Linux\u5b66\u4e60\u7b14\u8bb0"},"content":{"rendered":"<p>\u4e00\u3001\u90e8\u7f72\u6587\u4ef6\u5230\u53d7\u7ba1\u4e3b\u673a<\/p>\n<p>\u7ea2\u5e3dAnsible\u5f15\u64ce\u672c\u8eab\u5185\u7f6e\u9644\u5e26\u4e86\u5927\u578b\u6a21\u5757\u96c6\u5408(\u6a21\u5757\u5e93)&#xff0c;Files \u6a21\u5757\u5e93\u5305\u542b\u7684\u6a21\u5757\u5141\u8bb8\u60a8\u5b8c\u6210\u4e0eLinux\u6587\u4ef6\u7ba1\u7406\u76f8\u5173\u7684\u5927\u591a\u6570\u4efb\u52a1&#xff0c;\u5982\u521b\u5efa\u3001\u590d\u5236\u3001\u7f16\u8f91\u548c\u4fee\u6539\u6587\u4ef6\u7684\u6743\u9650\u548c\u5176\u4ed6\u5c5e\u6027&#xff0c;\u4e0b\u8868\u5217\u51fa\u4e86\u5e38\u7528\u7684Files\u6a21\u5757\u5e93\u4e2d\u4f7f\u7528\u7684\u6a21\u5757\u3002<\/p>\n<p>file&#xff1a;\u8bbe\u7f6e\u6743\u9650\u3001\u6240\u6709\u6743\u3001SELinux\u4e0a\u4e0b\u6587\u4ee5\u53ca\u5e38\u89c4\u6587\u4ef6\u3001\u7b26\u53f7\u94fe\u63a5\u3001\u786c\u94fe\u63a5\u548c\u76ee\u5f55\u7684\u65f6\u95f4\u6233\u7b49\u5c5e\u6027\u3002\u6b64\u6a21\u5757\u8fd8\u53ef\u4ee5\u521b\u5efa\u6216\u5220\u9664\u5e38\u89c4\u6587\u4ef6\u3001\u7b26\u53f7\u94fe\u63a5\u3001\u786c\u94fe\u63a5\u548c\u76ee\u5f55\u3002<\/p>\n<p>sefcontext&#xff0c;\u8bbe\u7f6e\u6301\u4e45selinux\u4e0a\u4e0b\u6587\u3002<\/p>\n<p>lineinfile&#xff1a;\u786e\u4fdd\u7279\u5b9a\u884c\u4f4d\u4e8e\u67d0\u4e2a\u6587\u4ef6\u4e2d&#xff0c;\u6216\u4f7f\u7528\u53cd\u5411\u5f15\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u66ff\u6362\u73b0\u6709\u884c\u3002<\/p>\n<p>replace&#xff1a;\u67e5\u627e\u6587\u4ef6\u4e2d\u884c&#xff0c;\u4e00\u6b21\u6027\u66ff\u6362\u6210\u5bf9\u5e94\u5185\u5bb9\u3002<\/p>\n<p>blockinfile&#xff1a;\u63d2\u5165\u3001\u66f4\u65b0\u6216\u5220\u9664\u591a\u884c\u6587\u672c\u5757\u3002<\/p>\n<p>stat&#xff1a;\u68c0\u7d22\u6587\u4ef6\u7684\u72b6\u6001\u4fe1\u606f&#xff0c;\u7c7b\u4f3c\u4e8eLinux stat\u547d\u4ee4\u3002<\/p>\n<p>copy&#xff1a;\u5c06\u6587\u4ef6\u4ece\u672c\u5730\u6216\u8fdc\u7a0b\u8ba1\u7b97\u673a\u590d\u5236\u5230\u53d7\u7ba1\u8282\u70b9\u4e0a\u7684\u67d0\u4e2a\u4f4d\u7f6e\u3002<\/p>\n<p>synchronize&#xff1a;\u56f4\u7ed5rsync\u547d\u4ee4\u7684\u4e00\u4e2a\u7a0b\u5e8f&#xff0c;\u53ef\u52a0\u5feb\u548c\u7b80\u5316\u5e38\u89c1\u4efb\u52a1\u3002<\/p>\n<p>fetch&#xff1a;\u7528\u4e8e\u4ece\u8fdc\u7a0b\u8ba1\u7b97\u673a\u83b7\u53d6\u6587\u4ef6\u5230\u63a7\u5236\u8282\u70b9\u3002<\/p>\n<p>1.file \u6a21\u5757<\/p>\n<p>\u00a0#\u521b\u5efa\u6587\u4ef6<br \/>\n\u00a0vim touch.yaml<br \/>\n\u00a0&#8212;<br \/>\n\u00a0&#8211; hosts: node1<br \/>\n\u00a0  gather_facts: no<br \/>\n\u00a0  tasks:<br \/>\n\u00a0 \u00a0 \u00a0&#8211; name: Touch a file and set permissions<br \/>\n\u00a0 \u00a0 \u00a0  file:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  path: \/tmp\/testfile<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  owner: zhangzhe<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  group: wheel<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  mode: 0640<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  state: touch<br \/>\n\u00a0&#8230;<br \/>\n\u00a0#\u9a8c\u8bc1<br \/>\n\u00a0ansible-playbook touch.yaml<br \/>\n\u00a0#\u521b\u5efa\u76ee\u5f55<br \/>\n\u00a0vim mkdir.yaml<br \/>\n\u00a0&#8212;<br \/>\n\u00a0&#8211; hosts: node1<br \/>\n\u00a0  gather_facts: no<br \/>\n\u00a0  tasks:<br \/>\n\u00a0 \u00a0 \u00a0&#8211; name: create directory<br \/>\n\u00a0 \u00a0 \u00a0  file:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  path: \/webdev<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  owner: zhangzhe<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  group: wheel<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  mode: 0755<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  state: directory<br \/>\n\u00a0&#8230;<br \/>\n\u00a0#\u9a8c\u8bc1<br \/>\n\u00a0ansible-playbook mkdir.yaml<br \/>\n\u00a0#\u5220\u9664\u6587\u4ef6<br \/>\n\u00a0vim rm.yaml<br \/>\n\u00a0&#8212;<br \/>\n\u00a0&#8211; hosts: node1<br \/>\n\u00a0  gather_facts: no<br \/>\n\u00a0  tasks:<br \/>\n\u00a0 \u00a0 \u00a0&#8211; name: delete file<br \/>\n\u00a0 \u00a0 \u00a0  file:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  path: \/tmp\/testfile<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  state: absent<br \/>\n\u00a0&#8230;<br \/>\n\u00a0#\u9a8c\u8bc1<br \/>\n\u00a0ansible-playbook rm.yaml<\/p>\n<p>2.lineinfile\u6a21\u5757<\/p>\n<p>\u00a0#\u5728\u6587\u4ef6\u4e2d\u63d2\u5165\u884c<br \/>\n\u00a0vim lineinfile.yaml<br \/>\n\u00a0&#8212;<br \/>\n\u00a0&#8211; hosts: node1<br \/>\n\u00a0  gather_facts: no<br \/>\n\u00a0  tasks:<br \/>\n\u00a0 \u00a0 \u00a0&#8211; name: add line<br \/>\n\u00a0 \u00a0 \u00a0  lineinfile:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  path: \/webdev\/testfile<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  line: &#039;zhangzhe&#039;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0#insertbefore\u5728\u76ee\u6807\u524d\u63d2\u5165&#xff0c;insertafter\u5728\u76ee\u6807\u540e\u63d2\u5165<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  insertafter: &#039;hello world1&#039;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  state: present<br \/>\n\u00a0&#8230;<br \/>\n\u00a0#\u9a8c\u8bc1<br \/>\n\u00a0ansible-playbook lineinfile.yaml<\/p>\n<p>3.replace\u6a21\u5757<\/p>\n<p>\u00a0#\u5339\u914d\u5185\u5bb9\u5168\u90e8\u66ff\u6362<br \/>\n\u00a0vim replace.yaml<br \/>\n\u00a0&#8212;<br \/>\n\u00a0&#8211; hosts: node1<br \/>\n\u00a0  gather_facts: no<br \/>\n\u00a0  tasks:<br \/>\n\u00a0 \u00a0 \u00a0&#8211; name: replace multi line<br \/>\n\u00a0 \u00a0 \u00a0  replace:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  path: \/webdev\/testfile<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  regexp: &#039;old line&#039;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  replace: &#039;new line&#039;<br \/>\n\u00a0&#8230;<br \/>\n\u00a0#\u9a8c\u8bc1<br \/>\n\u00a0ansible-playbook replace.yaml<\/p>\n<p>4.copy\u6a21\u5757<\/p>\n<p>\u00a0#\u5c06\u63a7\u5236\u8282\u70b9\u4e0a\u7684\u6587\u4ef6\u62f7\u8d1d\u5230\u53d7\u7ba1\u7406\u8282\u70b9&#xff0c;\u7c7b\u4f3c\u4e8eLinux\u4e2dscp\u547d\u4ee4<br \/>\n\u00a0vim copy.yaml<br \/>\n\u00a0&#8212;<br \/>\n\u00a0&#8211; hosts: node1<br \/>\n\u00a0  gather_facts: no<br \/>\n\u00a0  tasks:<br \/>\n\u00a0 \u00a0 \u00a0&#8211; name: copy \/home\/zhangzhe\/webapp\/inventory to remote node<br \/>\n\u00a0 \u00a0 \u00a0  copy:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  src: \/home\/zhangzhe\/webapp\/inventory<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  dest: \/webdev<br \/>\n\u00a0&#8230;<br \/>\n\u00a0#\u9a8c\u8bc1<br \/>\n\u00a0ansible-playbook copy.yaml<\/p>\n<p>\u4e8c\u3001\u7ba1\u7406\u53d8\u91cf<\/p>\n<p>ansible \u5229\u7528\u53d8\u91cf\u6765\u5b58\u50a8\u6570\u636e&#xff0c;\u4ee5\u4fbf\u5728Ansible\u9879\u76ee\u6587\u4ef6\u4e2d\u91cd\u590d\u5f15\u7528&#xff0c;\u6709\u5229\u4e8e\u7b80\u5316\u9879\u76ee\u7684\u521b\u5efa\u548c\u7ef4\u62a4&#xff0c;\u964d\u4f4e\u51fa\u9519\u7387\u3002\u6211\u4eec\u5728playbook\u4e2d\u53ef\u4ee5\u9488\u5bf9\u5982\u7528\u6237\u3001\u8f6f\u4ef6\u5305\u3001\u670d\u52a1\u3001\u6587\u4ef6\u7b49\u8fdb\u884c\u53d8\u91cf\u5b9a\u4e49\u3002<\/p>\n<p>\u53d8\u91cf\u8303\u56f4\u548c\u4f18\u5148\u7ea7<\/p>\n<p>ansible\u9879\u76ee\u6587\u4ef6\u4e2d\u591a\u4e2a\u4f4d\u7f6e\u652f\u6301\u5b9a\u4e49\u53d8\u91cf&#xff0c;\u4e3b\u8981\u5305\u542b\u4e09\u4e2a\u57fa\u672c\u8303\u56f4&#xff1a;<\/p>\n<p>Global scope&#xff1a;\u4ece\u547d\u4ee4\u884c\u6216 Ansible \u914d\u7f6e\u8bbe\u7f6e\u7684\u53d8\u91cf\u3002<\/p>\n<p>Play scope&#xff1a;\u5728play\u548c\u76f8\u5173\u7ed3\u6784\u4e2d\u8bbe\u7f6e\u7684\u53d8\u91cf\u3002<\/p>\n<p>Host scope&#xff1a;\u7531\u6e05\u5355\u3001\u4e8b\u5b9e&#xff08;fact&#xff09;\u6536\u96c6\u6216\u6ce8\u518c\u7684\u4efb\u52a1&#xff0c;\u5728\u4e3b\u673a\u7ec4\u548c\u4e2a\u522b\u4e3b\u673a\u4e0a\u8bbe\u7f6e\u7684\u53d8\u91cf\u3002<\/p>\n<p>\u4f18\u5148\u7ea7\u4ece\u9ad8\u5230\u4f4e\u987a\u5e8f&#xff1a;Global &gt; Play &gt; Host\u3002<\/p>\n<p>\u5728\u591a\u4e2a\u7ea7\u522b\u4e0a\u5b9a\u4e49\u4e86\u76f8\u540c\u540d\u79f0\u7684\u53d8\u91cf&#xff0c;\u5219\u91c7\u7528\u4f18\u5148\u7ea7\u522b\u6700\u9ad8\u7684\u53d8\u91cf\u3002<\/p>\n<p>1.Global scope<\/p>\n<p>\u00a0#\u901a\u8fc7\u9009\u9879 -e \u4f20\u9012\u7ed9ansible\u6216ansible-playbook\u547d\u4ee4<br \/>\n\u00a0ansible node1 -m debug -a &#034;msg&#061;{{ package }}&#034; -e &#034;package&#061;httpd&#034;<br \/>\n\u00a0\u200b<br \/>\n\u00a0node1 | SUCCESS &#061;&gt; {<br \/>\n\u00a0 \u00a0 \u00a0&#034;msg&#034;: &#034;httpd&#034;<br \/>\n\u00a0}<br \/>\n\u00a0\u200b<br \/>\n\u00a0ansible node1 -m yum -a &#034;name&#061;{{ package }} state&#061;present &#034; -e &#034;package&#061;httpd&#034;<br \/>\n\u00a0\u200b<br \/>\n\u00a0node1 | SUCCESS &#061;&gt; {<br \/>\n\u00a0 \u00a0 \u00a0&#034;ansible_facts&#034;: {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0&#034;discovered_interpreter_python&#034;: &#034;\/usr\/bin\/python&#034;<br \/>\n\u00a0 \u00a0  },<br \/>\n\u00a0 \u00a0 \u00a0&#034;changed&#034;: false,<br \/>\n\u00a0 \u00a0 \u00a0&#034;msg&#034;: &#034;&#034;,<br \/>\n\u00a0 \u00a0 \u00a0&#034;rc&#034;: 0,<br \/>\n\u00a0 \u00a0 \u00a0&#034;results&#034;: [<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0&#034;httpd-2.4.6-99.el7.centos.1.x86_64 providing httpd is already installed&#034;<br \/>\n\u00a0 \u00a0  ]<br \/>\n\u00a0}<\/p>\n<p>2.Play scope<\/p>\n<p>\u00a0# vars \u58f0\u660e<br \/>\n\u00a0vim vars.yaml<br \/>\n\u00a0&#8212;<br \/>\n\u00a0&#8211; name: test vars statement in play<br \/>\n\u00a0  hosts: node1<br \/>\n\u00a0  vars:<br \/>\n\u00a0 \u00a0  user: joe<br \/>\n\u00a0 \u00a0  home: \/home\/joe<br \/>\n\u00a0  tasks:<br \/>\n\u00a0 \u00a0 \u00a0&#8211; name: add user {{ user }}<br \/>\n\u00a0 \u00a0 \u00a0  user:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0#&#xff1a;\u540e\u8ddf {{ \u53d8\u91cf }} \u9700\u8981\u5e26\u53cc\u5f15\u53f7\u201c\u201d<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  name: &#034;{{ user }}&#034;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  home: &#034;{{ home }}&#034;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  state: present<br \/>\n\u00a0\u200b<br \/>\n\u00a0 \u00a0 \u00a0&#8211; name: debug user<br \/>\n\u00a0 \u00a0 \u00a0  debug:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  msg: |<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0  username is {{ user }}<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0  home is {{ home }}<br \/>\n\u00a0&#8230;<br \/>\n\u00a0#\u9a8c\u8bc1<br \/>\n\u00a0ansible-playbook vars.yaml<br \/>\n\u00a0\u200b<br \/>\n\u00a0# vars_files \u58f0\u660e<br \/>\n\u00a0#\u5982\u679c\u53d8\u91cf\u6bd4\u8f83\u591a&#xff0c;\u6211\u4e48\u53ef\u4ee5\u4f7f\u7528\u53d8\u91cf\u6587\u4ef6\u8fdb\u884c\u5206\u7c7b&#xff0c;\u7136\u540e\u5206\u5217\u522b\u5e94\u7528\u5230playbook\u4e2d\u3002<br \/>\n\u00a0vim user1.yaml<br \/>\n\u00a0user: user1<br \/>\n\u00a0home: \/home\/user1<br \/>\n\u00a0vim vars_file.yaml<br \/>\n\u00a0&#8212;<br \/>\n\u00a0&#8211; name: test vars statement in play<br \/>\n\u00a0  hosts: webs<br \/>\n\u00a0 \u00a0#vars_files:<br \/>\n\u00a0 \u00a0#  &#8211; \/home\/zhangzhe\/webapp\/user1.yaml<br \/>\n\u00a0  tasks:<br \/>\n\u00a0 \u00a0 \u00a0&#8211; name: add user {{ user }}<br \/>\n\u00a0 \u00a0 \u00a0  user:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  name: &#034;{{ user }}&#034;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0#home: &#034;{{ home }}&#034;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  state: present<br \/>\n\u00a0\u200b<br \/>\n\u00a0 \u00a0 \u00a0&#8211; name: debug user<br \/>\n\u00a0 \u00a0 \u00a0  debug:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  msg: &gt;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0  username is {{ user }}<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0#home is {{ home }}<br \/>\n\u00a0&#8230;<br \/>\n\u00a0#\u9a8c\u8bc1<br \/>\n\u00a0ansible-playbook vars_file.yaml<\/p>\n<p>3.Host scope<\/p>\n<p>\u4e3b\u673a\u53d8\u91cf\u5e94\u7528\u4e8e\u4e3b\u673a\u548c\u4e3b\u673a\u7ec4\u3002\u4e3b\u673a\u53d8\u91cf\u4f18\u5148\u7ea7\u9ad8\u4e8e\u4e3b\u673a\u7ec4\u53d8\u91cf\u3002<\/p>\n<p>\u00a0#\u4e3b\u673a\u6e05\u5355\u4e2d\u5b9a\u4e49<br \/>\n\u00a0vim inventory<br \/>\n\u00a0[webs]<br \/>\n\u00a0node1 user&#061;zhangsan<br \/>\n\u00a0node2<br \/>\n\u00a0\u200b<br \/>\n\u00a0[webs:vars]<br \/>\n\u00a0user&#061;lisi<br \/>\n\u00a0#\u9a8c\u8bc1<br \/>\n\u00a0ansible webs -m debug -a &#039; msg&#061;&#034;hello,{{ user }}&#034;&#039;<\/p>\n<p>4.\u76ee\u5f55\u5206\u5c42\u7ed3\u6784\u5b9a\u4e49<\/p>\n<p>\u00a0cat inventory<br \/>\n\u00a0\u200b<br \/>\n\u00a0[controllers]<br \/>\n\u00a0controller<br \/>\n\u00a0\u200b<br \/>\n\u00a0[webs]<br \/>\n\u00a0node1<br \/>\n\u00a0node2<br \/>\n\u00a0\u200b<br \/>\n\u00a0[dbs]<br \/>\n\u00a0node3<br \/>\n\u00a0node4<br \/>\n\u00a0\u200b<br \/>\n\u00a0[nodes]<br \/>\n\u00a0node[1:4]<br \/>\n\u00a0\u200b<br \/>\n\u00a0mkdir host_vars group_vars<br \/>\n\u00a0echo &#034;user: laoma&#034; &gt; host_vars\/node1.yml<br \/>\n\u00a0echo &#034;user: laowang&#034; &gt; group_vars\/webs.yml<br \/>\n\u00a0#\u9a8c\u8bc1<br \/>\n\u00a0ansible nodes -m debug -a &#039; msg&#061;&#034;hello,{{ user }}&#034;&#039;<\/p>\n<p>5.\u6570\u7ec4\u53d8\u91cf<\/p>\n<p>\u00a0vim shuzu.yaml<br \/>\n\u00a0&#8212;<br \/>\n\u00a0&#8211; name: test vars statement in play<br \/>\n\u00a0  hosts: node1<br \/>\n\u00a0  vars:<br \/>\n\u00a0 \u00a0  users:<br \/>\n\u00a0 \u00a0 \u00a0  laoma:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  user_name: laoma<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  home_path: \/home\/laoma<br \/>\n\u00a0 \u00a0 \u00a0  laowang:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  user_name: laowang<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  home_path: \/home\/laowang<br \/>\n\u00a0  tasks:<br \/>\n\u00a0 \u00a0 \u00a0&#8211; name: add user {{ users.laoma.user_name }}<br \/>\n\u00a0 \u00a0 \u00a0  user:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  name: &#039;{{ users.laoma.user_name }}&#039;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  home: &#034;{{ users.laoma.home_path }}&#034;<br \/>\n\u00a0\u200b<br \/>\n\u00a0 \u00a0 \u00a0&#8211; name: debug laowang<br \/>\n\u00a0 \u00a0 \u00a0  debug:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  msg: &gt;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0  username is {{ users[&#039;laowang&#039;][&#039;user_name&#039;] }}<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0  home_path is {{ users[&#039;laowang&#039;][&#039;home_path&#039;] }}<br \/>\n\u00a0&#8230;<br \/>\n\u00a0#\u9a8c\u8bc1<br \/>\n\u00a0ansible-playbook shuzu.yaml<\/p>\n<p>6.\u4e3b\u673a\u8fde\u63a5\u7279\u6b8a\u53d8\u91cf<\/p>\n<p>ansible_connection&#xff0c;\u4e0e\u4e3b\u673a\u7684\u8fde\u63a5\u7c7b\u578b&#xff0c;\u53ef\u4ee5\u662f smart\u3001ssh \u6216 paramiko\u3002\u9ed8\u8ba4\u4e3asmart\u3002<\/p>\n<p>ansible_host&#xff0c;\u8981\u8fde\u63a5\u7684\u4e3b\u673a\u7684\u540d\u79f0&#xff0c;\u9ed8\u8ba4\u503c\u5c31\u662f\u4e3b\u673a\u6e05\u5355\u540d\u79f0\u3002<\/p>\n<p>ansible_port&#xff0c;ssh \u7aef\u53e3\u53f7&#xff0c;\u5982\u679c\u4e0d\u662f 22\u3002<\/p>\n<p>ansible_user&#xff0c;ssh \u7528\u6237\u540d\u3002<\/p>\n<p>ansible_ssh_pass&#xff0c;\u8981\u4f7f\u7528\u7684 ssh \u5bc6\u7801\u3002\u5207\u52ff\u4ee5\u7eaf\u6587\u672c\u5f62\u5f0f\u5b58\u50a8\u6b64\u53d8\u91cf&#xff0c;\u59cb\u7ec8\u4f7f\u7528\u4fdd\u7ba1\u5e93\u3002<\/p>\n<p>ansible_ssh_private_key_file&#xff0c;ssh \u4f7f\u7528\u7684\u79c1\u94a5\u6587\u4ef6\u3002\u5982\u679c\u4f7f\u7528\u591a\u4e2a\u5bc6\u94a5\u5e76\u4e14\u60a8\u4e0d\u60f3\u4f7f\u7528SSH \u4ee3\u7406&#xff0c;\u8fd9\u5f88\u6709\u7528\u3002<\/p>\n<p>ansible_ssh_common_args&#xff0c;\u6b64\u8bbe\u7f6e\u59cb\u7ec8\u9644\u52a0\u5230 sftp\u3001scp \u548c ssh \u7684\u9ed8\u8ba4\u547d\u4ee4\u884c\u3002<\/p>\n<p>ansible_sftp_extra_args&#xff0c;\u6b64\u8bbe\u7f6e\u59cb\u7ec8\u9644\u52a0\u5230\u9ed8\u8ba4\u7684 sftp \u547d\u4ee4\u884c\u3002<\/p>\n<p>ansible_scp_extra_args&#xff0c;\u6b64\u8bbe\u7f6e\u59cb\u7ec8\u9644\u52a0\u5230\u9ed8\u8ba4\u7684 scp \u547d\u4ee4\u884c\u3002<\/p>\n<p>ansible_ssh_extra_args&#xff0c;\u6b64\u8bbe\u7f6e\u59cb\u7ec8\u9644\u52a0\u5230\u9ed8\u8ba4\u7684 ssh \u547d\u4ee4\u884c\u3002<\/p>\n<p>ansible_become&#xff0c;\u7b49\u6548\u4e8e ansible_sudo \u6216 ansible_su&#xff0c;\u5141\u8bb8\u5f3a\u5236\u63d0\u6743\u3002<\/p>\n<p>ansible_become_method&#xff0c;\u5141\u8bb8\u8bbe\u7f6e\u6743\u9650\u63d0\u5347\u65b9\u6cd5\u3002<\/p>\n<p>ansible_become_user&#xff0c;\u7b49\u6548\u4e8e ansible_sudo_user \u6216 ansible_su_user&#xff0c;\u5141\u8bb8\u8bbe\u7f6e\u60a8\u901a\u8fc7\u6743\u9650\u5347\u7ea7\u6210\u4e3a\u7684\u7528\u6237\u3002<\/p>\n<p>ansible_become_pass&#xff0c;\u7b49\u6548\u4e8e ansible_sudo_pass \u6216 ansible_su_pass&#xff0c;\u5141\u8bb8\u60a8\u8bbe\u7f6e\u6743\u9650\u63d0\u5347\u5bc6\u7801&#xff08;\u5207\u52ff\u4ee5\u7eaf\u6587\u672c\u5f62\u5f0f\u5b58\u50a8\u6b64\u53d8\u91cf&#xff1b;\u59cb\u7ec8\u4f7f\u7528\u4fdd\u7ba1\u5e93\u3002\u8bf7\u53c2\u9605\u53d8\u91cf\u548c\u4fdd\u7ba1\u5e93&#xff09;\u3002<\/p>\n<p>7.MAGIC \u53d8\u91cf<\/p>\n<p>magic \u53d8\u91cf\u7531 Ansible \u81ea\u52a8\u8bbe\u7f6e&#xff0c;\u53ef\u7528\u4e8e\u83b7\u53d6\u4e0e\u7279\u5b9a\u53d7\u7ba1\u4e3b\u673a\u76f8\u5173\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u00a0#\u6700\u5e38\u7528\u7684\u56db\u4e2aMagic\u53d8\u91cf<br \/>\n\u00a0ansible node1 -m debug -a &#039;var&#061;inventory_hostname&#039;<br \/>\n\u00a0ansible node1 -m debug -a &#039;var&#061;group_names&#039;<br \/>\n\u00a0ansible node1 -m debug -a &#039;var&#061;groups&#039;<br \/>\n\u00a0ansible node1 -m debug -a &#039;var&#061;hostvars&#039;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u90e8\u7f72\u6587\u4ef6\u5230\u53d7\u7ba1\u4e3b\u673a\u7ea2\u5e3dAnsible\u5f15\u64ce\u672c\u8eab\u5185\u7f6e\u9644\u5e26\u4e86\u5927\u578b\u6a21\u5757\u96c6\u5408(\u6a21\u5757\u5e93)&#xff0c;Files \u6a21\u5757\u5e93\u5305\u542b\u7684\u6a21\u5757\u5141\u8bb8\u60a8\u5b8c\u6210\u4e0eLinux\u6587\u4ef6\u7ba1\u7406\u76f8\u5173\u7684\u5927\u591a\u6570\u4efb\u52a1&#xff0c;\u5982\u521b\u5efa\u3001\u590d\u5236\u3001\u7f16\u8f91\u548c\u4fee\u6539\u6587\u4ef6\u7684\u6743\u9650\u548c\u5176\u4ed6\u5c5e\u6027&#xff0c;\u4e0b\u8868\u5217\u51fa\u4e86\u5e38\u7528\u7684Files\u6a21\u5757\u5e93\u4e2d\u4f7f\u7528\u7684\u6a21\u5757\u3002file&#xff1a;\u8bbe\u7f6e\u6743\u9650\u3001\u6240\u6709\u6743\u3001SELinux\u4e0a\u4e0b\u6587\u4ee5\u53ca\u5e38\u89c4\u6587\u4ef6\u3001\u7b26\u53f7\u94fe\u63a5\u3001\u786c\u94fe\u63a5\u548c\u76ee\u5f55\u7684\u65f6\u95f4\u6233\u7b49\u5c5e\u6027\u3002\u6b64\u6a21\u5757\u8fd8\u53ef\u4ee5\u521b\u5efa\u6216\u5220\u9664\u5e38\u89c4\u6587\u4ef6\u3001\u7b26\u53f7\u94fe\u63a5\u3001\u786c\u94fe\u63a5\u548c\u76ee\u5f55\u3002sefcontex<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[58,371,43,305,44],"topic":[],"class_list":["post-59480","post","type-post","status-publish","format-standard","hentry","category-server","tag-linux","tag-371","tag-43","tag-305","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>20260113Linux\u5b66\u4e60\u7b14\u8bb0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/59480.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"20260113Linux\u5b66\u4e60\u7b14\u8bb0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001\u90e8\u7f72\u6587\u4ef6\u5230\u53d7\u7ba1\u4e3b\u673a\u7ea2\u5e3dAnsible\u5f15\u64ce\u672c\u8eab\u5185\u7f6e\u9644\u5e26\u4e86\u5927\u578b\u6a21\u5757\u96c6\u5408(\u6a21\u5757\u5e93)&#xff0c;Files \u6a21\u5757\u5e93\u5305\u542b\u7684\u6a21\u5757\u5141\u8bb8\u60a8\u5b8c\u6210\u4e0eLinux\u6587\u4ef6\u7ba1\u7406\u76f8\u5173\u7684\u5927\u591a\u6570\u4efb\u52a1&#xff0c;\u5982\u521b\u5efa\u3001\u590d\u5236\u3001\u7f16\u8f91\u548c\u4fee\u6539\u6587\u4ef6\u7684\u6743\u9650\u548c\u5176\u4ed6\u5c5e\u6027&#xff0c;\u4e0b\u8868\u5217\u51fa\u4e86\u5e38\u7528\u7684Files\u6a21\u5757\u5e93\u4e2d\u4f7f\u7528\u7684\u6a21\u5757\u3002file&#xff1a;\u8bbe\u7f6e\u6743\u9650\u3001\u6240\u6709\u6743\u3001SELinux\u4e0a\u4e0b\u6587\u4ee5\u53ca\u5e38\u89c4\u6587\u4ef6\u3001\u7b26\u53f7\u94fe\u63a5\u3001\u786c\u94fe\u63a5\u548c\u76ee\u5f55\u7684\u65f6\u95f4\u6233\u7b49\u5c5e\u6027\u3002\u6b64\u6a21\u5757\u8fd8\u53ef\u4ee5\u521b\u5efa\u6216\u5220\u9664\u5e38\u89c4\u6587\u4ef6\u3001\u7b26\u53f7\u94fe\u63a5\u3001\u786c\u94fe\u63a5\u548c\u76ee\u5f55\u3002sefcontex\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/59480.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-13T15:05:03+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/59480.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/59480.html\",\"name\":\"20260113Linux\u5b66\u4e60\u7b14\u8bb0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-13T15:05:03+00:00\",\"dateModified\":\"2026-01-13T15:05:03+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/59480.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/59480.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/59480.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"20260113Linux\u5b66\u4e60\u7b14\u8bb0\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"20260113Linux\u5b66\u4e60\u7b14\u8bb0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/59480.html","og_locale":"zh_CN","og_type":"article","og_title":"20260113Linux\u5b66\u4e60\u7b14\u8bb0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u3001\u90e8\u7f72\u6587\u4ef6\u5230\u53d7\u7ba1\u4e3b\u673a\u7ea2\u5e3dAnsible\u5f15\u64ce\u672c\u8eab\u5185\u7f6e\u9644\u5e26\u4e86\u5927\u578b\u6a21\u5757\u96c6\u5408(\u6a21\u5757\u5e93)&#xff0c;Files \u6a21\u5757\u5e93\u5305\u542b\u7684\u6a21\u5757\u5141\u8bb8\u60a8\u5b8c\u6210\u4e0eLinux\u6587\u4ef6\u7ba1\u7406\u76f8\u5173\u7684\u5927\u591a\u6570\u4efb\u52a1&#xff0c;\u5982\u521b\u5efa\u3001\u590d\u5236\u3001\u7f16\u8f91\u548c\u4fee\u6539\u6587\u4ef6\u7684\u6743\u9650\u548c\u5176\u4ed6\u5c5e\u6027&#xff0c;\u4e0b\u8868\u5217\u51fa\u4e86\u5e38\u7528\u7684Files\u6a21\u5757\u5e93\u4e2d\u4f7f\u7528\u7684\u6a21\u5757\u3002file&#xff1a;\u8bbe\u7f6e\u6743\u9650\u3001\u6240\u6709\u6743\u3001SELinux\u4e0a\u4e0b\u6587\u4ee5\u53ca\u5e38\u89c4\u6587\u4ef6\u3001\u7b26\u53f7\u94fe\u63a5\u3001\u786c\u94fe\u63a5\u548c\u76ee\u5f55\u7684\u65f6\u95f4\u6233\u7b49\u5c5e\u6027\u3002\u6b64\u6a21\u5757\u8fd8\u53ef\u4ee5\u521b\u5efa\u6216\u5220\u9664\u5e38\u89c4\u6587\u4ef6\u3001\u7b26\u53f7\u94fe\u63a5\u3001\u786c\u94fe\u63a5\u548c\u76ee\u5f55\u3002sefcontex","og_url":"https:\/\/www.wsisp.com\/helps\/59480.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-13T15:05:03+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/59480.html","url":"https:\/\/www.wsisp.com\/helps\/59480.html","name":"20260113Linux\u5b66\u4e60\u7b14\u8bb0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-13T15:05:03+00:00","dateModified":"2026-01-13T15:05:03+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/59480.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/59480.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/59480.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"20260113Linux\u5b66\u4e60\u7b14\u8bb0"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/59480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=59480"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/59480\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=59480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=59480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=59480"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=59480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}