<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss
  version="2.0"
  xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  
>
  <channel>
    <title>Ansible on 从左到东</title>
    <link>/tags/ansible/</link>
    <description>Recent content in Ansible on 从左到东</description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    <lastBuildDate>Thu, 21 Nov 2024 13:30:41 +0800</lastBuildDate>
    <atom:link href="/tags/ansible/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>ansible</title>
      <link>/post/%E6%8A%80%E6%9C%AF%E7%9B%B8%E5%85%B3/%E5%B8%B8%E7%94%A8%E5%B7%A5%E5%85%B7/ansible/</link>
      <pubDate>Thu, 21 Nov 2024 13:30:41 +0800</pubDate>
      <guid>/post/%E6%8A%80%E6%9C%AF%E7%9B%B8%E5%85%B3/%E5%B8%B8%E7%94%A8%E5%B7%A5%E5%85%B7/ansible/</guid>
      <description>&lt;ol&gt;&#xA;&lt;li&gt;安装&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;yum -y install ansible&lt;/p&gt;&#xA;&lt;p&gt;ansible &amp;ndash;version&lt;/p&gt;&#xA;&lt;ol start=&#34;2&#34;&gt;&#xA;&lt;li&gt;添加控制机器&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;ssh-copy-id -i .ssh/id_rsa.pub &lt;a href=&#34;mailto:root@192.168.100.20&#34;&gt;root@192.168.100.20&lt;/a&gt;&lt;/p&gt;&#xA;&lt;ol start=&#34;3&#34;&gt;&#xA;&lt;li&gt;添加到hosts文件中&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;vim /etc/ansible/hosts&lt;/p&gt;&#xA;&lt;p&gt;Ansible 通过设备列表以分组的方式添加到 /etc/ansible/hosts 文件来实现对设备的管理，所以在正式管理之前，首先要编写好 hosts 文件。hosts 文件中，以[ ]包含的部分代表组名，设备列表支持主机名和IP地址。&lt;/p&gt;&#xA;&lt;p&gt;默认情况下，通过访问22端口（SSH）来管理设备。若目标主机使用了非默认的SSH端口，还可以在主机名称之后使用冒号加端口标明，以行为单位分隔配置。另外，hosts文件还支持通配符。&lt;/p&gt;&#xA;&lt;p&gt;[root@centos01 ~]# vim /etc/ansible/hosts&lt;/p&gt;&#xA;&lt;p&gt;&amp;hellip;&amp;hellip;&amp;hellip;&amp;hellip;&lt;/p&gt;&#xA;&lt;p&gt;[web]&lt;/p&gt;&#xA;&lt;p&gt;192.168.100.20&lt;/p&gt;&#xA;&lt;p&gt;192.168.100.30&lt;/p&gt;&#xA;&lt;p&gt;[test]&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://www.benet.com&#34;&gt;www.benet.com&lt;/a&gt;:222&lt;/p&gt;&#xA;&lt;p&gt;[mail]&lt;/p&gt;&#xA;&lt;p&gt;yj1.kgc.cn&lt;/p&gt;&#xA;&lt;p&gt;yj[2:5].kgc.cn&lt;/p&gt;&#xA;&lt;p&gt;可以将一个主机同时归置在不同的组中。&lt;/p&gt;&#xA;&lt;p&gt;配置完成之后，可以针对hosts定义的组进行远程操作，也可以针对组中的某一个或多个主机操作。例如：&lt;/p&gt;&#xA;&lt;p&gt;1）只对web组中192.168.1.2主机操作，通过—limit参数限定主机的变更。&lt;/p&gt;&#xA;&lt;p&gt;[root@centos01 ~]# ansible web -m command -a &amp;ldquo;systemctl status httpd&amp;rdquo; &amp;ndash;limit &amp;ldquo;192.168.100.20&amp;rdquo;&lt;/p&gt;&#xA;&lt;p&gt;192.168.100.20 | SUCCESS | rc=0 &amp;raquo;&lt;/p&gt;&#xA;&lt;p&gt;2）只对192.168.100.20主机操作。通过IP限定主机的变更。&lt;/p&gt;&#xA;&lt;p&gt;[root@centos01 ~]# ansible 192.168.100.20 -m command -a &amp;ldquo;systemctl status httpd&amp;rdquo;&lt;/p&gt;&#xA;&lt;p&gt;192.168.100.20 | SUCCESS | rc=0 &amp;raquo;&lt;/p&gt;</description>
      
    </item>
  </channel>
</rss>
