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

@@ -13,7 +13,7 @@
"articleSection" : "post",
"name" : "[ansible] 引用事先定義好的yaml檔裡面的變數 - Ansible Selectattr From List in Dictionary file",
"headline" : "[ansible] 引用事先定義好的yaml檔裡面的變數 - Ansible Selectattr From List in Dictionary file",
"description" : "\x3cp\x3e在ansible中關於如何引用自定義的變數一直讓我很頭疼\x3c\/p\x3e\n\x3cp\x3e尤其是有牽涉到從外部導入yaml檔案時更是常常讓我不知道到底該怎麼抓出想要的變數\x3c\/p\x3e\n\x3cp\x3e這次還是用selectattr 來處理,希望下次能夠記得\x26hellip;\x3c\/p\x3e",
"description" : "\u003cp\u003e在ansible中關於如何引用自定義的變數一直讓我很頭疼\u003c\/p\u003e\n\u003cp\u003e尤其是有牽涉到從外部導入yaml檔案時更是常常讓我不知道到底該怎麼抓出想要的變數\u003c\/p\u003e\n\u003cp\u003e這次還是用selectattr 來處理,希望下次能夠記得\u0026hellip;\u003c\/p\u003e",
"inLanguage" : "en",
"author" : "Eric Chang",
"creator" : "Eric Chang",
@@ -21,8 +21,8 @@
"accountablePerson" : "Eric Chang",
"copyrightHolder" : "Eric Chang",
"copyrightYear" : "2019",
"datePublished": "2019-07-01 09:06:12 \x2b0800 CST",
"dateModified" : "2019-07-01 09:06:12 \x2b0800 CST",
"datePublished": "2019-07-01 09:06:12 \u002b0800 CST",
"dateModified" : "2019-07-01 09:06:12 \u002b0800 CST",
"url" : "https:\/\/h.cowbay.org\/post\/ansible-selectattr-from-list-in-dictionary\/",
"wordCount" : "150",
"image" : "https://h.cowbay.orghttps://h.cowbay.org/images/post-default-7.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">
@@ -308,7 +308,7 @@ if (!doNotTrack) {
<p>尤其是有牽涉到從外部導入yaml檔案時更是常常讓我不知道到底該怎麼抓出想要的變數</p>
<p>這次還是用selectattr 來處理,希望下次能夠記得&hellip;</p>
<p>首先是導入的yaml檔案內容長這樣</p>
<pre><code>client_hosts:
<pre tabindex="0"><code>client_hosts:
abc.com:
- host: hqdc021
ipv4: 192.168.11.21
@@ -350,17 +350,17 @@ if (!doNotTrack) {
</code></pre><p>在playbook中首先先導入這個檔案</p>
<pre><code>- name: load client_host
<pre tabindex="0"><code>- name: load client_host
include_vars:
file: client_hosts.yml
name: ch
</code></pre><p>然後用這個剛剛導入的檔案,去做出想要的清單</p>
<p>像底下這個就是指定了client_hosts的 abc.com 這個域名底下iuser有被定義的資料再轉成list</p>
<pre><code>- name: get internet user list
<pre tabindex="0"><code>- name: get internet user list
set_fact:
iuser_list: &quot;{{ ch['client_host']['abc.com']|selectattr('iuser','defined')|list }}&quot;
</code></pre><p>然後就可以用來做condition了</p>
<pre><code>- name: copy environment block to /etc/environment
<pre tabindex="0"><code>- name: copy environment block to /etc/environment
copy:
content: |
PATH=&quot;/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games&quot;
@@ -658,7 +658,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>