回答編集履歴

3

コード修正

2021/09/30 09:25

投稿

comefigo
comefigo

スコア1045

test CHANGED
@@ -17,6 +17,46 @@
17
17
  異なるホストの変数を取得したい時はどうするのかというと`hostvars[ホスト名]`から取得できます。
18
18
 
19
19
  `hostvars`をデバックしてみて頂ければピンとくるかと思います。
20
+
21
+
22
+
23
+ ```yaml
24
+
25
+ - name: debugテスト
26
+
27
+ hosts: all
28
+
29
+ user: Administrator
30
+
31
+ gather_facts: no
32
+
33
+ environment:
34
+
35
+ no_proxy: 127.0.0.1,localhost
36
+
37
+ tasks:
38
+
39
+ - name: Get disk facts
40
+
41
+ community.windows.win_disk_facts:
42
+
43
+
44
+
45
+ - set_fact:
46
+
47
+ disksize_gib_human: '{{ disk.size|filesizeformat(true) }}'
48
+
49
+ disksize_gib: '{{ (disk.size/1024|pow(3))|round|int }} GiB'
50
+
51
+ disksize_gb_human: '{{ disk.size|filesizeformat }}'
52
+
53
+ disksize_gb: '{{ (disk.size/1000|pow(3))|round|int }} GB'
54
+
55
+
56
+
57
+ ```
58
+
59
+
20
60
 
21
61
 
22
62
 
@@ -50,6 +90,14 @@
50
90
 
51
91
  with_dict: "{{ hostvars }}"
52
92
 
93
+
94
+
95
+ # ANSIBLE-2019で定義されたもしくは読み込まれた変数を表示します。
96
+
97
+ - debug:
98
+
99
+ msg: "{{ hostvars['ANSIBLE-2019'] }}"
100
+
53
101
  ```
54
102
 
55
103
 

2

デバックコードを追記

2021/09/30 09:25

投稿

comefigo
comefigo

スコア1045

test CHANGED
@@ -22,7 +22,33 @@
22
22
 
23
23
  ```yaml
24
24
 
25
+ # item.keyはホスト名
26
+
27
+ # item.valueはそのホストで使用可能な変数
28
+
29
+ #
30
+
31
+ # hostvarsは以下のような構造になっています
32
+
33
+ #
34
+
35
+ # -------------------------------------
36
+
37
+ # hostvars[host1][disksize_gib_human]
38
+
39
+ # [disksize_gib]
40
+
41
+ # hostvars[host2][disksize_gib_human]
42
+
43
+ # [[disksize_gib]]
44
+
45
+ # --------------------------------------
46
+
47
+ - debug:
48
+
49
+ msg: "{{ item.key }}"
50
+
25
- - debug: msg="{{ hostvars }}"
51
+ with_dict: "{{ hostvars }}"
26
52
 
27
53
  ```
28
54
 

1

文書校正

2021/09/30 06:12

投稿

comefigo
comefigo

スコア1045

test CHANGED
@@ -1,4 +1,4 @@
1
- playのdegugテストで各ホストで`win_disk_facts`した結果を各変数に格納しています。
1
+ playのdegugテストで各ホストで`win_disk_facts`した結果を各変数に格納しています。
2
2
 
3
3
  それらの変数は競合しないように**ホストごと**に管理されています。
4
4
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  例えば、host1とhost2がある場合は、host1のdisksize_gib_humanとhost2のdisksize_gib_humanがそれぞれ管理されています。
8
8
 
9
- つまり、host1でdisksize_gib_humanを呼び出した時や値を格納するときはhost1のdisksize_gib_humanが使われます。
9
+ つまり、host1でdisksize_gib_humanを呼び出した時や値を格納するときはhost1のdisksize_gib_humanが使われます。host2のdisksize_gib_humanに影響はない。
10
10
 
11
11
 
12
12