<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>ansible | 伪架构师</title>
    <link>/tags/ansible/</link>
      <atom:link href="/tags/ansible/index.xml" rel="self" type="application/rss+xml" />
    <description>ansible</description>
    <generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>zh</language><lastBuildDate>Mon, 09 May 2016 19:26:49 +0800</lastBuildDate>
    <image>
      <url>/img/logo-wide.png</url>
      <title>ansible</title>
      <link>/tags/ansible/</link>
    </image>
    
    <item>
      <title>Ansible Playbook 拼接字符串</title>
      <link>/post/concat-string-in-ansible/</link>
      <pubDate>Mon, 09 May 2016 19:26:49 +0800</pubDate>
      <guid>/post/concat-string-in-ansible/</guid>
      <description>&lt;p&gt;目前使用 Playbook 方式进行部署的一般是集群系统，面对不定数量的一组 Host，经常需要利用这一组主机的信息来拼接为一个字符串，以此结果设置为变量，其他需要集群信息的配置文件/命令行参数就可以引用这一信息了。&lt;/p&gt;

&lt;p&gt;下面代码以一组 Host 生成形如 &lt;code&gt;server1=ip1:port,server2=ip1:port&lt;/code&gt; 的结果。&lt;/p&gt;

&lt;p&gt;Host 信息：&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[node]
10.211.55.78
10.211.55.79
10.211.55.80
&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code class=&#34;language-yaml&#34;&gt;- name: storage
  set_fact: host_list=&amp;quot;{{ groups[&#39;node&#39;] }}&amp;quot;
- name: combine
  set_fact: host_list=&amp;quot;{% for item in host_list %} node{{ item.split(&amp;quot;.&amp;quot;)[2] }}_{{ item.split(&amp;quot;.&amp;quot;)[3]}}=http://{{item}}:{{ node_peer_port }} {% endfor %}&amp;quot;
- name: display
  set_fact: cluster_hosts={{ host_list.split() | join(&amp;quot;,&amp;quot;) }}
- name: debug
  debug: var=cluster_hosts
&lt;/code&gt;&lt;/pre&gt;
</description>
    </item>
    
  </channel>
</rss>
