update some content

This commit is contained in:
2021-10-28 14:13:06 +08:00
parent 97eb780aa4
commit 4f99455d8f
242 changed files with 1826 additions and 2616 deletions

View File

@@ -11,9 +11,9 @@
"@id": "https:\/\/h.cowbay.org"
},
"articleSection" : "post",
"name" : "[筆記] Ansible how to use \x27list\x27 in yaml file ",
"headline" : "[筆記] Ansible how to use \x27list\x27 in yaml file ",
"description" : "\x3cp\x3e這幾天在玩ansible 時,碰到一個問題\x3c\/p\x3e\n\x3cp\x3e假如我有個yaml檔作為資料來源檔名是 abc.yml\x3c\/p\x3e\n\x3cp\x3e大概長這樣\x3c\/p\x3e\n\x3cpre\x3e\x3ccode\x3e \x26quot;teams\x26quot;: [\n {\n \x26quot;chinese_name\x26quot;: \x26quot;TEAM1\x26quot;,\n \x26quot;description\x26quot;: \x26quot;TEAM1\x26quot;,\n \x26quot;gid\x26quot;: 10125,\n \x26quot;location\x26quot;: [\n \x26quot;hq\x26quot;\n ],\n \x26quot;name\x26quot;: \x26quot;aa\x26quot;,\n \x26quot;users\x26quot;: [\n \x26quot;chen\x26quot;,\n \x26quot;chou\x26quot;,\n \x26quot;huani\x26quot;,\n \x26quot;yey\x26quot;,\n \x26quot;wa\x26quot;\n ]\n },\n {\n \x26quot;chinese_name\x26quot;: \x26quot;TEAM2\x26quot;,\n \x26quot;description\x26quot;: \x26quot;TEAM2\x26quot;,\n \x26quot;gid\x26quot;: 10126,\n \x26quot;location\x26quot;: [\n \x26quot;hq\x26quot;\n ],\n \x26quot;name\x26quot;: \x26quot;bb\x26quot;,\n \x26quot;users\x26quot;: [\n \x26quot;chhiao\x26quot;,\n \x26quot;chgc\x26quot;,\n \x26quot;chy\x26quot;,\n \x26quot;hsi\x26quot;,\n \x26quot;li\x26quot;,\n \x26quot;li\x26quot;,\n \x26quot;chgchi\x26quot;\n ]\n }\n\t\t]\n\t\t\n\x3c\/code\x3e\x3c\/pre\x3e",
"name" : "[筆記] Ansible how to use \u0027list\u0027 in yaml file ",
"headline" : "[筆記] Ansible how to use \u0027list\u0027 in yaml file ",
"description" : "\u003cp\u003e這幾天在玩ansible 時,碰到一個問題\u003c\/p\u003e\n\u003cp\u003e假如我有個yaml檔作為資料來源檔名是 abc.yml\u003c\/p\u003e\n\u003cp\u003e大概長這樣\u003c\/p\u003e\n\u003cpre tabindex=\u00220\u0022\u003e\u003ccode\u003e \u0026quot;teams\u0026quot;: [\n {\n \u0026quot;chinese_name\u0026quot;: \u0026quot;TEAM1\u0026quot;,\n \u0026quot;description\u0026quot;: \u0026quot;TEAM1\u0026quot;,\n \u0026quot;gid\u0026quot;: 10125,\n \u0026quot;location\u0026quot;: [\n \u0026quot;hq\u0026quot;\n ],\n \u0026quot;name\u0026quot;: \u0026quot;aa\u0026quot;,\n \u0026quot;users\u0026quot;: [\n \u0026quot;chen\u0026quot;,\n \u0026quot;chou\u0026quot;,\n \u0026quot;huani\u0026quot;,\n \u0026quot;yey\u0026quot;,\n \u0026quot;wa\u0026quot;\n ]\n },\n {\n \u0026quot;chinese_name\u0026quot;: \u0026quot;TEAM2\u0026quot;,\n \u0026quot;description\u0026quot;: \u0026quot;TEAM2\u0026quot;,\n \u0026quot;gid\u0026quot;: 10126,\n \u0026quot;location\u0026quot;: [\n \u0026quot;hq\u0026quot;\n ],\n \u0026quot;name\u0026quot;: \u0026quot;bb\u0026quot;,\n \u0026quot;users\u0026quot;: [\n \u0026quot;chhiao\u0026quot;,\n \u0026quot;chgc\u0026quot;,\n \u0026quot;chy\u0026quot;,\n \u0026quot;hsi\u0026quot;,\n \u0026quot;li\u0026quot;,\n \u0026quot;li\u0026quot;,\n \u0026quot;chgchi\u0026quot;\n ]\n }\n\t\t]\n\t\t\n\u003c\/code\u003e\u003c\/pre\u003e",
"inLanguage" : "en",
"author" : "Eric Chang",
"creator" : "Eric Chang",
@@ -21,8 +21,8 @@
"accountablePerson" : "Eric Chang",
"copyrightHolder" : "Eric Chang",
"copyrightYear" : "2018",
"datePublished": "2018-11-27 16:50:53 \x2b0800 CST",
"dateModified" : "2018-11-27 16:50:53 \x2b0800 CST",
"datePublished": "2018-11-27 16:50:53 \u002b0800 CST",
"dateModified" : "2018-11-27 16:50:53 \u002b0800 CST",
"url" : "https:\/\/h.cowbay.org\/post\/ansible-selectattr\/",
"wordCount" : "219",
"image" : "https://h.cowbay.orghttps://h.cowbay.org/images/post-default-1.jpg"",
@@ -45,9 +45,9 @@
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<link href="https://h.cowbay.org/css/style.css?v=1632901488" rel="stylesheet" id="theme-stylesheet" type='text/css' media='all'>
<link href="https://h.cowbay.org/css/style.css?v=1634607506" rel="stylesheet" id="theme-stylesheet" type='text/css' media='all'>
<link href="https://h.cowbay.org/css/custom.css?v=1632901488" rel="stylesheet" type='text/css' media='all'>
<link href="https://h.cowbay.org/css/custom.css?v=1634607506" rel="stylesheet" type='text/css' media='all'>
<link rel="shortcut icon" href="https://h.cowbay.org/img/favicon.ico" type="image/x-icon">
<link rel="icon" href="https://h.cowbay.org/img/favicon.ico" type="image/x-icon">
@@ -307,7 +307,7 @@ if (!doNotTrack) {
<p>這幾天在玩ansible 時,碰到一個問題</p>
<p>假如我有個yaml檔作為資料來源檔名是 abc.yml</p>
<p>大概長這樣</p>
<pre><code> &quot;teams&quot;: [
<pre tabindex="0"><code> &quot;teams&quot;: [
{
&quot;chinese_name&quot;: &quot;TEAM1&quot;,
&quot;description&quot;: &quot;TEAM1&quot;,
@@ -345,7 +345,7 @@ if (!doNotTrack) {
]
</code></pre><p>稍微整理一下,比較容易看</p>
<pre><code> &quot;teams&quot;: [
<pre tabindex="0"><code> &quot;teams&quot;: [
{
&quot;chinese_name&quot;: &quot;TEAM1&quot;,
&quot;description&quot;: &quot;TEAM1&quot;,
@@ -365,7 +365,7 @@ if (!doNotTrack) {
]
</code></pre><p>在 ansible playbook 中,我用 include_vars 把這個檔案叫進來</p>
<pre><code>- name: load teams.yml
<pre tabindex="0"><code>- name: load teams.yml
tags: env
include_vars:
file: files/kw/teams.yml
@@ -374,7 +374,7 @@ if (!doNotTrack) {
<p>那如果我想要用users這個清單中的id作為建立帳號的來源</p>
<p>我就可以用底下這段,先把 users 裡面的內容,指給 dc_users 這個 localvar</p>
<p>然後加上 when 的條件,限定只有 name == aa 的 users 才會被指定給 dc_users</p>
<pre><code>- name: set aa_users
<pre tabindex="0"><code>- name: set aa_users
tags: env
set_fact:
aa_users: &quot;{{ item.users }}&quot;
@@ -382,7 +382,7 @@ if (!doNotTrack) {
with_items: &quot;{{ teams }}&quot;
</code></pre><p>這樣子執行下來是沒有問題的,不過就是醜了點 XD</p>
<p>之後要抓 user 帳號時,就可以直接用 aa_users 來跑迴圈</p>
<pre><code>- name: create folder for aa_users
<pre tabindex="0"><code>- name: create folder for aa_users
tags: env
file:
path: &quot;/tmp/{{ item }}&quot;
@@ -395,7 +395,7 @@ if (!doNotTrack) {
<p>p.s 講話一定要參雜用英文單字,這樣看起來比較屌&hellip;</p>
<p>所以沒辦法直接在底下的create folder task 直接叫出來</p>
<p>如果直接叫 teams.users ,那會是一個清單</p>
<pre><code> [&quot;chen&quot;,&quot;chou&quot;,&quot;huani&quot;,&quot;yey&quot;,&quot;wa&quot;]
<pre tabindex="0"><code> [&quot;chen&quot;,&quot;chou&quot;,&quot;huani&quot;,&quot;yey&quot;,&quot;wa&quot;]
</code></pre><p>然後 ansible 也很厲害,就這個樣子,他還是會去忠實的執行建立目錄</p>
<p>所以在 /tmp 底下就會多出一個</p>
<blockquote>
@@ -693,7 +693,7 @@ title="pinterest icon"></i>
</div>
<script src="https://h.cowbay.org/js/jquery.min.js"></script>
<script src="https://h.cowbay.org/js/jquerymigrate.js"></script>
<script src="https://h.cowbay.org/js/production.min.js?v=1632901488"></script>
<script src="https://h.cowbay.org/js/production.min.js?v=1634607506"></script>
</body>
</html>