add auto fetch ssl certs

This commit is contained in:
2021-08-26 12:11:25 +08:00
parent 11ca254bed
commit 509ac048fc
237 changed files with 4968 additions and 7406 deletions

View File

@@ -13,7 +13,7 @@
"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\n\x3cp\x3e假如我有個yaml檔作為資料來源檔名是 abc.yml\x3c\/p\x3e\n\n\x3cp\x3e大概長這樣\x3c\/p\x3e\n\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",
"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",
"inLanguage" : "en",
"author" : "Eric Chang",
"creator" : "Eric Chang",
@@ -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=1626744134" rel="stylesheet" id="theme-stylesheet" type='text/css' media='all'>
<link href="https://h.cowbay.org/css/style.css?v=1629951055" rel="stylesheet" id="theme-stylesheet" type='text/css' media='all'>
<link href="https://h.cowbay.org/css/custom.css?v=1626744134" rel="stylesheet" type='text/css' media='all'>
<link href="https://h.cowbay.org/css/custom.css?v=1629951055" 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">
@@ -81,10 +81,6 @@ if (!doNotTrack) {
<ul id="menu-secondary-items" class="menu-secondary-items">
<li class="menu-item menu-item-type-taxonomy menu-item-object-category">
<a href="/categories/"></a>
</li>
<li class="menu-item menu-item-type-taxonomy menu-item-object-category">
<a href="/categories/ansible">ansible</a>
</li>
@@ -309,11 +305,8 @@ if (!doNotTrack) {
<div class="entry-content">
<article>
<p>這幾天在玩ansible 時,碰到一個問題</p>
<p>假如我有個yaml檔作為資料來源檔名是 abc.yml</p>
<p>大概長這樣</p>
<pre><code> &quot;teams&quot;: [
{
&quot;chinese_name&quot;: &quot;TEAM1&quot;,
@@ -351,10 +344,7 @@ if (!doNotTrack) {
}
]
</code></pre>
<p>稍微整理一下,比較容易看</p>
</code></pre><p>稍微整理一下,比較容易看</p>
<pre><code> &quot;teams&quot;: [
{
&quot;chinese_name&quot;: &quot;TEAM1&quot;,
@@ -374,38 +364,24 @@ if (!doNotTrack) {
}
]
</code></pre>
<p>在 ansible playbook 中,我用 include_vars 把這個檔案叫進來</p>
</code></pre><p>在 ansible playbook 中,我用 include_vars 把這個檔案叫進來</p>
<pre><code>- name: load teams.yml
tags: env
include_vars:
file: files/kw/teams.yml
</code></pre>
<p>這時候在這個執行階段,就會有一個變數叫 teams 裡面有 chinese_name/description/gid 等等這些屬性</p>
</code></pre><p>這時候在這個執行階段,就會有一個變數叫 teams 裡面有 chinese_name/description/gid 等等這些屬性</p>
<p>其中的 location/users 又是另外一個 list</p>
<p>那如果我想要用users這個清單中的id作為建立帳號的來源</p>
<p>我就可以用底下這段,先把 users 裡面的內容,指給 dc_users 這個 localvar</p>
<p>然後加上 when 的條件,限定只有 name == aa 的 users 才會被指定給 dc_users</p>
<pre><code>- name: set aa_users
tags: env
set_fact:
aa_users: &quot;{{ item.users }}&quot;
when: item.name == 'aa'
with_items: &quot;{{ teams }}&quot;
</code></pre>
<p>這樣子執行下來是沒有問題的,不過就是醜了點 XD</p>
</code></pre><p>這樣子執行下來是沒有問題的,不過就是醜了點 XD</p>
<p>之後要抓 user 帳號時,就可以直接用 aa_users 來跑迴圈</p>
<pre><code>- name: create folder for aa_users
tags: env
file:
@@ -414,35 +390,20 @@ if (!doNotTrack) {
group: &quot;{{ item }}&quot;
state: directory
with_items: &quot;{{ aa_users }}&quot;
</code></pre>
<p>很簡單的概念,因為一開始在 teams 這個 var 裡面</p>
</code></pre><p>很簡單的概念,因為一開始在 teams 這個 var 裡面</p>
<p>users 這個屬性是一個 list</p>
<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;]
</code></pre>
<p>然後 ansible 也很厲害,就這個樣子,他還是會去忠實的執行建立目錄</p>
</code></pre><p>然後 ansible 也很厲害,就這個樣子,他還是會去忠實的執行建立目錄</p>
<p>所以在 /tmp 底下就會多出一個</p>
<blockquote>
<p>[&ldquo;chen&rdquo;,&ldquo;chou&rdquo;,&ldquo;huani&rdquo;,&ldquo;yey&rdquo;,&ldquo;wa&rdquo;]</p>
</blockquote>
<p>這個樣子的目錄 &hellip;.</p>
<p>所以我的處理方式就是先把這個清單丟給一個local變數 ( aa_users )</p>
<p>後面的task再用這個 {{ aa_users }} 來跑,這樣子就 OK 了</p>
<p>雖說很簡單,但是卡了我一整天吶&hellip;</p>
</article>
</div>
@@ -720,7 +681,7 @@ title="pinterest icon"></i>
</ul> <div class="design-credit">
<p>&copy; 2018 Göran Svensson</p>
<p>© 2018 Göran Svensson</p>
<p>Nederburg Hugo Theme by <a href="https://appernetic.io">Appernetic</a>.</p>
@@ -732,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=1626744134"></script>
<script src="https://h.cowbay.org/js/production.min.js?v=1629951055"></script>
</body>
</html>