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中取得loop register後的值\/ Ansible Get Value From Loop Register",
"headline" : "[筆記]在ansible中取得loop register後的值\/ Ansible Get Value From Loop Register",
"description" : "\x3cp\x3e今天在寫一支客製化 firefox 的playbook\x3c\/p\x3e\n\n\x3cp\x3e因為firefox 會給每個user 建立一個由亂數字串組成的default profile\x3c\/p\x3e\n\n\x3cp\x3e所以每個user的 default profile 都不同\x3c\/p\x3e\n\n\x3cp\x3e也因此在用register處理的時候碰到了一些問題\x3c\/p\x3e",
"description" : "\x3cp\x3e今天在寫一支客製化 firefox 的playbook\x3c\/p\x3e\n\x3cp\x3e因為firefox 會給每個user 建立一個由亂數字串組成的default profile\x3c\/p\x3e\n\x3cp\x3e所以每個user的 default profile 都不同\x3c\/p\x3e\n\x3cp\x3e也因此在用register處理的時候碰到了一些問題\x3c\/p\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,39 +305,24 @@ if (!doNotTrack) {
<div class="entry-content">
<article>
<p>今天在寫一支客製化 firefox 的playbook</p>
<p>因為firefox 會給每個user 建立一個由亂數字串組成的default profile</p>
<p>所以每個user的 default profile 都不同</p>
<p>也因此在用register處理的時候碰到了一些問題</p>
<h3 id="task-內容">TASK 內容</h3>
<p>其實task 內容沒有很複雜簡單來說就是先檢查user的 firefox profile 目錄</p>
<p>如果存在就pass如果不存在就幫user建立</p>
<pre><code>- name: check if user profile exists
become_user: &quot;{{ item.name }}&quot;
stat:
path: &quot;{{ firefox_home }}&quot;
register: profile_exists
with_items: &quot;{{ users }}&quot;
</code></pre>
<p>但是在接下來的task在執行的時候碰到了問題</p>
</code></pre><p>但是在接下來的task在執行的時候碰到了問題</p>
<p>ansible 提示說profile_exists 沒有 stat 屬性</p>
<p>用過 stat module 的,應該都知道結果會是 var_name.stat.xxxx 這樣的用法</p>
<p>所以可以肯定的是 stat 這個屬性一定在</p>
<p>可是也一定有什麼問題,造成取不到值</p>
<p>當然就是先debug 來看看(有些不重要的屬性,我就先拿掉了)</p>
<pre><code>ok: [hqdc075] =&gt; {
&quot;profile_exists&quot;: {
&quot;changed&quot;: false,
@@ -402,40 +383,24 @@ if (!doNotTrack) {
&quot;exists&quot;: false,
}
},
</code></pre>
<p>一開始是先注意到了為什麼裡面還有 item ?</p>
</code></pre><p>一開始是先注意到了為什麼裡面還有 item ?</p>
<p>再往上看,就發現多了一個 results 把原本的list 清單給包起來了</p>
<p>所以原本用 profile_exists.stat.exists 可以取得目錄是否存在(true/false)</p>
<p>但是現在因為多了一層 results ,所以變成取不到值</p>
<p>沒關係,既然知道了有多了一層 results ,那就知道要怎麼做了</p>
<h3 id="修正後續task">修正後續task</h3>
<p>後面的task 稍微改一下,在指定 with_items 的時候,直接指定 profile_exists.results</p>
<p>接下來的用法就比較簡單了跟原本接stat 變數的語法差不多</p>
<pre><code>- name: run firefox to create default profile
become_user: &quot;{{ item.item.name }}&quot;
shell: &quot;firefox --headless &amp;&quot;
ignore_errors: True
when: item.stat.exists == false
with_items: &quot;{{ profile_exists.results }}&quot;
</code></pre>
<p>透過這次的playbook 又知道了怎麼承接 loop register 跑出來的值,又學了一課</p>
</code></pre><p>透過這次的playbook 又知道了怎麼承接 loop register 跑出來的值,又學了一課</p>
<p>本來一開始的想法是register dynamic variable name</p>
<p>像是 a_exist,b_exist,c_exist 這樣</p>
<p>不過ansible 不這樣處理,會自動的把所有結果都包在一個 results list 裡面</p>
<p>也算是還滿好用的啦</p>
</article>
</div>
@@ -711,7 +676,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>
@@ -723,7 +688,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>