{"id":16373,"date":"2025-04-18T22:52:10","date_gmt":"2025-04-18T14:52:10","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/16373.html"},"modified":"2025-04-18T22:52:10","modified_gmt":"2025-04-18T14:52:10","slug":"%e6%90%ad%e5%bb%ba%e5%9f%ba%e4%ba%8eansible%e7%9a%84%e6%9c%8d%e5%8a%a1%e5%99%a8%e8%87%aa%e5%8a%a8%e5%8c%96%e8%bf%90%e7%bb%b4%e7%ae%a1%e7%90%86%e5%b9%b3%e5%8f%b0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/16373.html","title":{"rendered":"\u642d\u5efa\u57fa\u4e8eAnsible\u7684\u670d\u52a1\u5668\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5e73\u53f0"},"content":{"rendered":"<h5 id=\"5a416d1b\">\u6838\u5fc3\u76ee\u6807<\/h5>\n<p id=\"u378eb05e\">\u5b9e\u73b0\u591a\u53f0\u670d\u52a1\u5668\u7684\u6279\u91cf\u5b89\u88c5\u7cfb\u7edf\u548cansible\u521d\u59cb\u5316\u3002<\/p>\n<h4><\/h4>\n<h4 id=\"a4e96beb\">1. \u5b9e\u9a8c\u73af\u5883\u51c6\u5907<\/h4>\n<h5 id=\"71ac43a5\">1.1 \u865a\u62df\u673a\u7f51\u7edc\u914d\u7f6e<\/h5>\n<ul>\n<li id=\"uf05bf2b2\">\u7f51\u7edc\u6a21\u5f0f&#xff1a;\u4f7f\u7528 Host-Only\u6a21\u5f0f&#xff0c;\u786e\u4fdd\u6240\u6709\u865a\u62df\u673a&#xff08;\u5305\u62ec\u63a7\u5236\u8282\u70b9&#xff09;\u5904\u4e8e\u540c\u4e00\u5c40\u57df\u7f51&#xff08;\u5982192.168.1.0\/24&#xff09;\u3002\u63a7\u5236\u8282\u70b9\u53ef\u4ee5\u589e\u52a0\u4e00\u4e2a\u865a\u62df\u7f51\u5361\u7528\u6765\u8bbf\u95ee\u5916\u7f51\u8d44\u6e90<\/li>\n<li id=\"u88bc0b2f\">\u63a7\u5236\u8282\u70b9&#xff1a;1\u53f0&#xff08;\u8bbf\u95ee\u5916\u7f51ip:192.1.100.141 pxe\u63a7\u5236IP&#xff1a;192.168.1.254&#xff09;&#xff0c;\u5b89\u88c5PXE\u670d\u52a1\u548cAnsible\u3002<\/li>\n<li id=\"uee3ebfce\">\u88ab\u7ba1\u7406\u8282\u70b9&#xff1a;3\u53f0\u865a\u62df\u673a&#xff0c;\u7f51\u5361\u8bbe\u7f6e\u4e3aPXE\u542f\u52a8<\/li>\n<\/ul>\n<h4 id=\"83416b46\">\u642d\u5efaPXE\u670d\u52a1\u5668&#xff08;\u63a7\u5236\u8282\u70b9\u64cd\u4f5c&#xff09;<\/h4>\n<h5 id=\"TH4Fy\">\u5173\u95ed\u9632\u706b\u5899&#xff0c;\u5173\u95edselinux<\/h5>\n<p>systemctl disable firewalld &#8211;now<br \/>\n setenforce 0<br \/>\nsudo sed -i &#034;s\/SELINUX&#061;enforcing\/SELINUX&#061;disabled\/&#034; \/etc\/selinux\/config <\/p>\n<p id=\"u72c2983f\">\n<h5 id=\"0c09c300\">\u5b89\u88c5\u4f9d\u8d56\u670d\u52a1<\/h5>\n<p>sudo yum install -y dhcp* tftp-server httpd syslinux<br \/>\nsudo systemctl enable dhcpd tftp httpd <\/p>\n<h5 id=\"4c5ee6b2\">\u914d\u7f6eDHCP\u670d\u52a1<\/h5>\n<p id=\"u1ba0f9de\">\u7f16\u8f91 \/etc\/dhcp\/dhcpd.conf&#xff1a;<\/p>\n<p>subnet 192.168.1.0 netmask 255.255.255.0 {<br \/>\n    range 192.168.1.200 192.168.1.220;       # IP\u5730\u5740\u6c60<br \/>\n    option routers 192.168.1.254;              # \u7f51\u5173<br \/>\n    option domain-name-servers 8.8.8.8;      # DNS<br \/>\n    filename &#034;pxelinux.0&#034;;                   # PXE\u5f15\u5bfc\u6587\u4ef6<br \/>\n    next-server 192.168.1.254;               # TFTP\u670d\u52a1\u5668IP&#xff08;\u63a7\u5236\u8282\u70b9&#xff09;<br \/>\n} <\/p>\n<p id=\"u5999946e\">\u91cd\u542f\u670d\u52a1&#xff1a;<\/p>\n<p id=\"udaa4e8bc\">sudo systemctl restart dhcpd<\/p>\n<p id=\"u0a56962c\">\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"63\" id=\"u48dbb0e8\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418145208-6802671872bb3.png\" width=\"773\" \/><\/p>\n<h5 id=\"47b17dad\">\u914d\u7f6eTFTP\u670d\u52a1<\/h5>\n<p># \u590d\u5236PXE\u5f15\u5bfc\u6587\u4ef6\u5230TFTP\u76ee\u5f55<br \/>\nsudo cp -r  \/usr\/share\/syslinux\/* \/var\/lib\/tftpboot\/<br \/>\nsudo mkdir -p \/var\/lib\/tftpboot\/pxelinux.cfg<\/p>\n<p># \u521b\u5efaPXE\u83dc\u5355\u914d\u7f6e\u6587\u4ef6<br \/>\nsudo vi \/var\/lib\/tftpboot\/pxelinux.cfg\/default <\/p>\n<p id=\"u96485242\">\u5185\u5bb9\u5982\u4e0b&#xff1a;<\/p>\n<p>default menu.c32<br \/>\ntimeout 2<br \/>\nprompt 0<\/p>\n<p>label linux<br \/>\n  menu label ^Install CentOS 8<br \/>\n  kernel vmlinuz<br \/>\n  append initrd&#061;initrd.img inst.repo&#061;http:\/\/192.168.1.254\/centos8 ks&#061;http:\/\/192.168.1.254\/ks.cfg      <\/p>\n<p id=\"u48b45650\">\u91cd\u542f\u670d\u52a1&#xff1a;<\/p>\n<p id=\"u58704b22\">sudo systemctl restart tftp<\/p>\n<h5 id=\"tNNfS\">\u914d\u7f6ehttp\u670d\u52a1<\/h5>\n<p>sudo mkdir \/var\/www\/html\/centos8<br \/>\nsudo mount \/dev\/sr0 \/var\/www\/html\/centos8<br \/>\n sudo systemctl enable httpd &#8211;now<br \/>\n  sudo cp -r \/var\/www\/html\/centos8\/isolinux\/{vmlinuz,initrd.img} \/var\/lib\/tftpboot\/ <\/p>\n<p id=\"u050c4878\">\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"81\" id=\"u9e5532dd\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418145208-6802671886ffa.png\" width=\"480\" \/><\/p>\n<p id=\"uedff26e2\">\n<h5 id=\"aeY1A\">\u914d\u7f6eKickstart<\/h5>\n<p id=\"uc8e71222\">\u5185\u5bb9\u5982\u4e0b&#xff08;\u7cbe\u7b80\u7248&#xff09;&#xff1a;<\/p>\n<p>[test&#064;control html]$ sudo cat ks.cfg<br \/>\n# Kickstart\u81ea\u52a8\u5b89\u88c5\u914d\u7f6e<br \/>\ninstall<br \/>\nurl &#8211;url&#061;http:\/\/192.168.1.254\/centos8  #\u5b89\u88c5\u6e90<br \/>\nlang en_US.UTF-8            #\u7f16\u7801<br \/>\nkeyboard us<br \/>\nnetwork &#8211;onboot yes &#8211;device eth0 &#8211;bootproto dhcp<br \/>\nrootpw &#8211;plaintext root    # \u8bbe\u7f6eroot\u5bc6\u7801<br \/>\nfirewall &#8211;disabled<br \/>\nselinux &#8211;disabled<br \/>\ntimezone Asia\/Shanghai<br \/>\nbootloader &#8211;location&#061;mbr<br \/>\nclearpart &#8211;all &#8211;initlabel<br \/>\npart \/ &#8211;fstype ext4 &#8211;size 10240  #\u6587\u4ef6\u7cfb\u7edf<br \/>\npart swap &#8211;size 2048<\/p>\n<p>%packages<br \/>\n&#064;^minimal<br \/>\n&#064;^graphical-server-environment  #\u8f6f\u4ef6\u5305\u5b89\u88c5<br \/>\nvim<br \/>\nnet-tools<br \/>\n%end<\/p>\n<p>%post  &#8211;nochroot                 #\u5728post\u90e8\u5206\u6dfb\u52a0\u91cd\u542f\u547d\u4ee4<br \/>\n# \u5b89\u88c5\u540e\u811a\u672c&#xff1a;\u5199\u5165\u5b8c\u6210\u6807\u8bb0<br \/>\necho &#034;PXE installation complete!&#034; &gt; \/root\/pxe_complete.txt #\u5b89\u88c5\u5b8c\u6210\u7684\u4fe1\u606f<br \/>\necho &#034;reboot&#034; &gt; \/root\/reboot.sh<br \/>\nchmod &#043;x \/root\/reboot.sh<br \/>\nbash \/reboot.sh<br \/>\n%end <\/p>\n<p id=\"u695aab08\">\u6743\u9650\u8bbe\u7f6e&#xff1a;<\/p>\n<p id=\"ub7303943\">sudo chmod 755 -R \/var\/lib\/tftp<\/p>\n<p id=\"u6a6a1584\">sudo chmod 755 -R \/var\/www\/html<\/p>\n<p id=\"u59b49cf9\">\n<h4 id=\"38c76336\">3. \u542f\u52a8\u865a\u62df\u673a\u5b89\u88c5\u7cfb\u7edf<\/h4>\n<h5 id=\"4bdc37c0\">3.1 \u8bbe\u7f6e\u865a\u62df\u673aPXE\u542f\u52a8<\/h5>\n<h5 id=\"jatWh\">\u81ea\u52a8\u5b89\u88c5\u8fc7\u7a0b<\/h5>\n<p id=\"u85953d37\">\u542f\u52a83\u53f0\u865a\u62df\u673a&#xff0c;\u5b83\u4eec\u4f1a\u901a\u8fc7PXE\u52a0\u8f7d\u5f15\u5bfc\u6587\u4ef6&#xff0c;\u81ea\u52a8\u4eceHTTP\u670d\u52a1\u5668\u4e0b\u8f7dKickstart\u914d\u7f6e\u3002<\/p>\n<p id=\"u1137f409\">\u7cfb\u7edf\u81ea\u52a8\u5b89\u88c5\u5b8c\u6210\u540e&#xff0c;\u865a\u62df\u673a\u4f1a\u91cd\u542f\u5e76\u8fdb\u5165\u65b0\u7cfb\u7edf\u3002<\/p>\n<p id=\"ud1cb509a\">VirtualBox\/VMware&#xff1a;\u57283\u53f0\u865a\u62df\u673a\u8bbe\u7f6e\u4e2d&#xff0c;\u5c06 \u7f51\u7edc\u542f\u52a8&#xff08;PXE&#xff09; \u8bbe\u4e3a\u7b2c\u4e00\u542f\u52a8\u9879\u3002<\/p>\n<p id=\"uee2d58ef\">\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"530\" id=\"u4da182e6\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418145208-6802671898abe.png\" width=\"643\" \/><\/p>\n<p id=\"ud43cdacf\">\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"245\" id=\"u2e9cb93c\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418145208-68026718b5593.png\" width=\"387\" \/><\/p>\n<p id=\"u7ccdfc27\">\n<p id=\"u22338d84\">\u9a8c\u8bc1&#xff1a;<\/p>\n<h5 id=\"0f1457a9\"><\/h5>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"189\" id=\"u0e476cc2\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418145208-68026718cb2ec.png\" width=\"724\" \/><\/p>\n<p id=\"ud74e65e9\">\n<p id=\"u9653f0e6\">\n<p id=\"u1aab8c42\">\n<h4 id=\"vbWHN\">\u5e38\u89c1\u9519\u8bef\u603b\u7ed3<\/h4>\n<table id=\"ogMlk\">\n<tbody>\n<tr>\n<td>\n<p id=\"u721ac1e8\">\u73b0\u8c61<\/p>\n<\/td>\n<td>\n<p id=\"u0bd702ff\">\u539f\u56e0<\/p>\n<\/td>\n<td>\n<p id=\"ub4469740\">\u89e3\u51b3\u65b9\u6848<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p id=\"uc982b662\">\u5b89\u88c5\u6e90\u4e0d\u53ef\u8fbe<\/p>\n<\/td>\n<td>\n<p id=\"u6c1dcc9c\">HTTP\u8def\u5f84\u9519\u8bef\u6216\u6743\u9650\u4e0d\u8db3<\/p>\n<\/td>\n<td>\n<p id=\"u4e5d5e9e\">\u68c0\u67e5 inst.repo<\/p>\n<p id=\"u993dd648\">\u548c url &#8211;url<\/p>\n<p id=\"uc942695f\">&#xff0c;\u4fee\u6b63\u6743\u9650<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p id=\"u7c37d072\">\u5206\u533a\u914d\u7f6e\u7f3a\u5931<\/p>\n<\/td>\n<td>\n<p id=\"u33186326\">Kickstart\u672a\u5b9a\u4e49 \/<\/p>\n<p id=\"u4f739717\">\u5206\u533a<\/p>\n<\/td>\n<td>\n<p id=\"u74b69895\">\u6dfb\u52a0 part \/ &#8211;fstype ext4 &#8211;size 10240<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p id=\"u93abdd58\">\u8f6f\u4ef6\u5305\u9009\u62e9\u9519\u8bef<\/p>\n<\/td>\n<td>\n<p id=\"u4fc26164\">%packages<\/p>\n<p id=\"u915c209a\">\u6bb5\u7f3a\u5931\u6216\u65e0\u6548<\/p>\n<\/td>\n<td>\n<p id=\"u99af5c0b\">\u6dfb\u52a0 &#064;^graphical-server-environment<\/p>\n<p id=\"u7468d78d\">\u6216\u6709\u6548\u5305\u7ec4<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p id=\"u40c81720\">\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4&#xff0c;\u53ef\u7cfb\u7edf\u6027\u89e3\u51b3PXE\u5b89\u88c5\u4e2d\u7684\u914d\u7f6e\u95ee\u9898\u3002\u5982\u679c\u4ecd\u65e0\u6cd5\u89e3\u51b3&#xff0c;\u53ef\u901a\u8fc7\u67e5\u770b\u5b89\u88c5\u754c\u9762\u7684 \u8be6\u7ec6\u65e5\u5fd7&#xff08;\u6309 Ctrl&#043;Alt&#043;F2 \u5207\u6362\u7ec8\u7aef&#xff09;\u8fdb\u4e00\u6b65\u5b9a\u4f4d\u9519\u8bef\u3002<\/p>\n<p id=\"u55e49b14\">\n<h4 id=\"Q5PzP\">ansible\u521d\u59cb\u5316<\/h4>\n<h5 id=\"HOIoI\">\u5b89\u88c5\u63a7\u5236\u7aefansible<\/h5>\n<p id=\"u7301ad79\">sudo yum install -y https:\/\/mirrors.aliyun.com\/epel\/epel-release-latest-8.noarch.rpm  \/\/\u5b89\u88c5epel\u6e90<\/p>\n<p id=\"ufe22f389\">sudo pip3 install ansible&#061;&#061;4.9.0 -i https:\/\/pypi.tuna.tsinghua.edu.cn\/simple  \/\/\u4f7f\u7528pip3\u4e0b\u8f7dansible&#xff0c;\u8fd9\u91cc\u662f\u7528\u56fd\u5185\u7684\u955c\u50cf\u6e90<\/p>\n<p id=\"uc9004187\">\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"347\" id=\"u3ed2841d\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418145208-68026718e0714.png\" width=\"770\" \/><\/p>\n<p id=\"u308c6ab2\">\n<h5 id=\"myI8e\">\u914d\u7f6eansible<\/h5>\n<h6 id=\"YlFvw\">\u73af\u5883\u642d\u5efa<\/h6>\n<p id=\"uaf208ec2\">\u56e0\u4e3a2.1\u7248\u672c\u9ed8\u8ba4\u662f\u6ca1\u6709\u914d\u7f6e\u6587\u4ef6\u7684&#xff0c;\u4f7f\u7528\u6211\u4eec\u8981\u5148\u521b\u5efaansible<\/p>\n<p id=\"u66916657\">mkdir \/etc\/ansible<\/p>\n<p id=\"ua8ffd2c0\">cd \/etc\/ansible\/<\/p>\n<p id=\"u8c83e91c\">sudo vi ansible.cfg<\/p>\n<p>[default]<br \/>\ninventory &#061; .\/inventory<br \/>\nremote_user &#061; user<br \/>\nask_pass &#061; false<\/p>\n<p>[privilege_escalation]<br \/>\nbecome &#061; true<br \/>\nbecome_method &#061; sudo<br \/>\nbecome_user &#061; root<br \/>\nbecome_ask_pass &#061; false <\/p>\n<p id=\"u9b1c50ea\">vi inventory<\/p>\n<p>[all_servers]<br \/>\nserver1 ansible_host&#061;192.168.1.204<br \/>\nserver2 ansible_host&#061;192.168.1.205  #\u5730\u5740\u662f\u56e0\u4e3a\u865a\u62df\u673a\u91cd\u88c5\u4e86&#xff0c;\u6b63\u5e38\u662f\u4ece201\u5f00\u59cb<br \/>\nserver3 ansible_host&#061;192.168.1.206<br \/>\nserver4 ansible_host&#061;192.168.1.207<\/p>\n<p>[all_servers:vars]<br \/>\nansible_ssh_user&#061;root<br \/>\nansible_ssh_pass&#061;root <\/p>\n<p id=\"u3250b43a\">\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"217\" id=\"u84fac31c\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418145209-680267191353a.png\" width=\"757\" \/><\/p>\n<p id=\"u9d6e00d7\">\n<p id=\"uf30604bc\">\u56e0\u4e3acentos8\u7684\u8f6f\u4ef6\u5e93\u4e2d\u79fb\u9664\u4e86sshpass\u5b89\u88c5\u5305&#xff0c;\u4f7f\u7528\u9700\u8981\u7f16\u7801\u4e0b\u8f7dsshpass<\/p>\n<p>sudo dnf install gcc make -y<br \/>\nwget https:\/\/sourceforge.net\/projects\/sshpass\/files\/latest\/download -O sshpass.tar.gz<br \/>\ntar -xvf sshpass.tar.gz<br \/>\ncd sshpass-1.10<br \/>\n.\/configure<br \/>\nmake<br \/>\nsudo make install <\/p>\n<p id=\"u46fb5f52\">vi \/etc\/hosts<\/p>\n<p> 192.168.1.204  server1<br \/>\n 192.168.1.205  server2<br \/>\n 192.168.1.206  server3<br \/>\n 192.168.1.207  server4 <\/p>\n<p id=\"u84218ba5\">\n<p id=\"u0f1b7f02\">ssh-keygen -t rsa -b 4096 #\u751f\u6210\u5bc6\u94a5\u6587\u4ef6<\/p>\n<p id=\"u0cc8866b\">mkdir playbooks<\/p>\n<p id=\"uc7ecd89a\">vi playbooks\/init_servers.yml<\/p>\n<p id=\"u1908794c\">\n<p>&#8211; name: Initialize Servers<br \/>\n  hosts: all_servers<br \/>\n  become: yes<\/p>\n<p>    &#8211; name: Deploy SSH Key<br \/>\n      ansible.posix.authorized_key:<br \/>\n        user: root<br \/>\n        key: &#034;{{ lookup(&#039;file&#039;, &#039;\/root\/.ssh\/id_rsa.pub&#039;) }}&#034;<br \/>\n        state: present<\/p>\n<p>    &#8211; name: Harden SSH<br \/>\n      template:<br \/>\n        src: &#034;templates\/sshd_config.j2&#034;<br \/>\n        dest: \/etc\/ssh\/sshd_config<br \/>\n      notify: Restart SSH<\/p>\n<p>    &#8211; name: copy ssh repo<br \/>\n      copy:<br \/>\n        src: \/etc\/ansible\/repo.sh<br \/>\n        dest: \/repo.sh<br \/>\n        mode: &#039;0755&#039;<br \/>\n    &#8211; name: execute the shell<br \/>\n      shell: \/repo.sh<br \/>\n    &#8211; name: Install Base Tools<br \/>\n      package:<br \/>\n        name:<br \/>\n          &#8211; vim<br \/>\n          &#8211; net-tools<br \/>\n        state: present<\/p>\n<p>  handlers:<br \/>\n    &#8211; name: Restart SSH<br \/>\n      systemd:<br \/>\n        name: sshd<br \/>\n        state: restarted <\/p>\n<p id=\"u108766a1\">mkdir templates<\/p>\n<p id=\"udc29113f\">vi templates\/sshd_config,j2<\/p>\n<p>port 2222<br \/>\nPermitRootLogin prohibit-password<br \/>\nPasswordAuthentication no <\/p>\n<p id=\"ubb159574\">sudo vi repo.sh<\/p>\n<p id=\"u2e464824\">\n<p>#!\/bin\/bash<br \/>\ncd \/etc\/yum.repos.d\/<br \/>\nmkdir bak<br \/>\nmv * bak<br \/>\necho &#034;[baseos]&#034; &gt;&gt; base.repo<br \/>\necho &#034;name&#061;baseos&#034; &gt;&gt; base.repo<br \/>\necho &#034;baseurl&#061;http:\/\/192.168.1.254\/centos8\/BaseOS&#034; &gt;&gt; base.repo<br \/>\necho &#034;gpgcheck&#061;0&#034; &gt;&gt; base.repo<\/p>\n<p>echo &#034;[appstream]&#034; &gt;&gt; base.repo<br \/>\necho &#034;name&#061;appstream&#034; &gt;&gt; base.repo<br \/>\necho &#034;baseurl&#061;http:\/\/192.168.1.254\/centos8\/AppStream&#034; &gt;&gt; base.repo<br \/>\necho &#034;gpgcheck&#061;0&#034; &gt;&gt; base.repo<\/p>\n<p>yum repolist <\/p>\n<p>\u00a0chmod 755 repo.sh<\/p>\n<p id=\"u5384ff06\">sudo chmod 644 -R templates<\/p>\n<p id=\"ufec33e08\">export ANSIBLE_HOST_KEY_CHECKING&#061;False<\/p>\n<p id=\"u2c12665d\">\/\/\u907f\u514d\u9996\u6b21\u8fde\u63a5\u65f6\u7684\u4ea4\u4e92\u63d0\u793a<\/p>\n<p id=\"ud8154db6\">ANSIBLE_HOST_KEY_CHECKING&#061;False #\u7528\u4e8e\u7981\u7528\u5728\u8fde\u63a5\u5230\u8fdc\u7a0b\u4e3b\u673a\u65f6\u8fdb\u884c SSH \u4e3b\u673a\u5bc6\u94a5\u68c0\u67e5<\/p>\n<p id=\"u1790d051\">sudo ANSIBLE_HOST_KEY_CHECKING&#061;False \/usr\/local\/bin\/ansible-playbook -i inventory init_servers.yml<\/p>\n<p id=\"u4c5dff85\">\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"320\" id=\"ud7cfc918\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418145209-680267192a044.png\" width=\"805\" \/><\/p>\n<p id=\"u3c5aa981\">\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"176\" id=\"u91450fdc\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418145209-680267194d52d.png\" width=\"723\" \/><\/p>\n<\/p>\n<p id=\"u7b1a20eb\">\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e34\u6b21\uff0c\u6536\u85cf29\u6b21\u3002pxe\u6279\u91cf\u90e8\u7f72centos8\u670d\u52a1\u5668\u5e76\u7f16\u5199playbook\u521d\u59cb\u5316\u57fa\u7840\u73af\u5883_ansible\u8fd0\u7ef4\u7ba1\u7406\u5e73\u53f0<\/p>\n","protected":false},"author":2,"featured_media":16364,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1064,43,44],"topic":[],"class_list":["post-16373","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-ansible","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u642d\u5efa\u57fa\u4e8eAnsible\u7684\u670d\u52a1\u5668\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5e73\u53f0 - \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\/16373.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u642d\u5efa\u57fa\u4e8eAnsible\u7684\u670d\u52a1\u5668\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5e73\u53f0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e34\u6b21\uff0c\u6536\u85cf29\u6b21\u3002pxe\u6279\u91cf\u90e8\u7f72centos8\u670d\u52a1\u5668\u5e76\u7f16\u5199playbook\u521d\u59cb\u5316\u57fa\u7840\u73af\u5883_ansible\u8fd0\u7ef4\u7ba1\u7406\u5e73\u53f0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/16373.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T14:52:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418145208-6802671872bb3.png\" \/>\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\/16373.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/16373.html\",\"name\":\"\u642d\u5efa\u57fa\u4e8eAnsible\u7684\u670d\u52a1\u5668\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5e73\u53f0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T14:52:10+00:00\",\"dateModified\":\"2025-04-18T14:52:10+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/16373.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/16373.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/16373.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u642d\u5efa\u57fa\u4e8eAnsible\u7684\u670d\u52a1\u5668\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5e73\u53f0\"}]},{\"@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":"\u642d\u5efa\u57fa\u4e8eAnsible\u7684\u670d\u52a1\u5668\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5e73\u53f0 - \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\/16373.html","og_locale":"zh_CN","og_type":"article","og_title":"\u642d\u5efa\u57fa\u4e8eAnsible\u7684\u670d\u52a1\u5668\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5e73\u53f0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e34\u6b21\uff0c\u6536\u85cf29\u6b21\u3002pxe\u6279\u91cf\u90e8\u7f72centos8\u670d\u52a1\u5668\u5e76\u7f16\u5199playbook\u521d\u59cb\u5316\u57fa\u7840\u73af\u5883_ansible\u8fd0\u7ef4\u7ba1\u7406\u5e73\u53f0","og_url":"https:\/\/www.wsisp.com\/helps\/16373.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T14:52:10+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418145208-6802671872bb3.png"}],"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\/16373.html","url":"https:\/\/www.wsisp.com\/helps\/16373.html","name":"\u642d\u5efa\u57fa\u4e8eAnsible\u7684\u670d\u52a1\u5668\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5e73\u53f0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T14:52:10+00:00","dateModified":"2025-04-18T14:52:10+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/16373.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/16373.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/16373.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u642d\u5efa\u57fa\u4e8eAnsible\u7684\u670d\u52a1\u5668\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5e73\u53f0"}]},{"@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\/16373","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=16373"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/16373\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/16364"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=16373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=16373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=16373"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=16373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}