質問編集履歴
11
該当コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -119,6 +119,6 @@
|
|
119
119
|
Delete hoge_web.logタスクの結果
|
120
120
|
```
|
121
121
|
# 下記の「Check hoge_web.logタスクのitemに渡される一覧の抜粋」が次々と渡されている様子
|
122
|
-
ok: [localhost] => (item=[{'invocation': {'module_args': {'checksum_algorithm': 'sha1', 'get_checksum': True, 'follow': False, 'path': '/home/hoge_hoge/hoge1.log', 'get_md5': False, 'get_mime': True, 'get_attributes': True}}, 'stat': {'charset': 'binary', 'uid': 0, 'exists': True, 'attr_flags': 'e', 'woth': False, 'isreg': True, 'device_type': 0, 'mtime': 1710652113.4640188, 'block_size': 4096, 'inode': 2416182, 'isgid': False, 'size': 1219, 'executable': False, 'roth': True, 'isuid': False, 'readable': True, 'version': '1282907058', 'pw_name': 'root', 'gid': 0, 'ischr': False, 'wusr': True, 'writeable': True, 'isdir': False, 'blocks': 8, 'xoth': False, 'rusr': True, 'nlink': 1, 'issock': False, 'rgrp': True, 'gr_name': 'root', 'path': '/home/hoge_hoge/hoge1.log', 'xusr': False, 'atime': 1710627251.1956754, 'mimetype': 'application/octet-stream', 'ctime': 1710652113.4640188, 'isblk': False, 'checksum': '4・・1b55・・・49a3d・・', 'dev': 64513, 'wgrp': False, 'isfifo': False, 'mode': '0644', 'xgrp': False, 'islnk': False, 'attributes': ['extents']}, 'changed': False, 'failed': False, 'item': 'saveMessage.log', 'ansible_loop_var': 'item'}, {'invocation': {'module_args': {'checksum_algorithm': 'sha1', 'get_checksum': True, 'follow': False, 'path': '/home/h
|
122
|
+
ok: [localhost] => (item=[{'invocation': {'module_args': {'checksum_algorithm': 'sha1', 'get_checksum': True, 'follow': False, 'path': '/home/hoge_hoge/hoge1.log', 'get_md5': False, 'get_mime': True, 'get_attributes': True}}, 'stat': {'charset': 'binary', 'uid': 0, 'exists': True, 'attr_flags': 'e', 'woth': False, 'isreg': True, 'device_type': 0, 'mtime': 1710652113.4640188, 'block_size': 4096, 'inode': 2416182, 'isgid': False, 'size': 1219, 'executable': False, 'roth': True, 'isuid': False, 'readable': True, 'version': '1282907058', 'pw_name': 'root', 'gid': 0, 'ischr': False, 'wusr': True, 'writeable': True, 'isdir': False, 'blocks': 8, 'xoth': False, 'rusr': True, 'nlink': 1, 'issock': False, 'rgrp': True, 'gr_name': 'root', 'path': '/home/hoge_hoge/hoge1.log', 'xusr': False, 'atime': 1710627251.1956754, 'mimetype': 'application/octet-stream', 'ctime': 1710652113.4640188, 'isblk': False, 'checksum': '4・・1b55・・・49a3d・・', 'dev': 64513, 'wgrp': False, 'isfifo': False, 'mode': '0644', 'xgrp': False, 'islnk': False, 'attributes': ['extents']}, 'changed': False, 'failed': False, 'item': 'saveMessage.log', 'ansible_loop_var': 'item'}, {'invocation': {'module_args': {'checksum_algorithm': 'sha1', 'get_checksum': True, 'follow': False, 'path': '/home/hoge_hoge/hoge2.log', 'get_md5': False, 'get_mime': True, 'get_attributes': True}}, 'stat': {'charset': 'us-ascii', 'uid': 0, 'exists': True, 'attr_flags': 'e', 'woth': False, 'isreg': True, 'device_type': 0, 'mtime': 1710652114.3400238, 'block_size': 4096, 'inode': 2416199, 'isgid': False, 'size': 1189, 'executable': False, 'roth': True, 'isuid': False, 'readable': True, 'version': '1282907076', 'pw_name': 'root', 'gid': 0, 'ischr': False, 'wusr': True, 'writeable': True, 'isdir': False, 'blocks': 8, 'xoth': False, 'rusr': True, 'nlink': 1, 'issock': False, 'rgrp': True, 'gr_name': 'root', 'path': '/home/hoge_hoge/hoge2.log', 'xusr': False, 'atime': 1710627252.0996804, 'mimetype': 'text/plain', 'ctime': 1710652114.3400238, 'isblk': False, 'checksum': '960b・・・deb55337b07', 'dev': 64513, 'wgrp': False, 'isfifo': False, 'mode': '0644', 'xgrp': False, 'islnk': False, 'attributes': ['extents']}, 'changed': False, 'failed': False, 'item': 'hoge2.log', 'ansible_loop_var': 'item'}])
|
123
123
|
```
|
124
124
|
|
10
該当コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -116,41 +116,9 @@
|
|
116
116
|
- "hoge_check.results"
|
117
117
|
when:
|
118
118
|
```
|
119
|
-
|
119
|
+
Delete hoge_web.logタスクの結果
|
120
120
|
```
|
121
|
-
|
122
|
-
{ ・
|
123
|
-
|
124
|
-
"ansible_loop_var": "item",
|
125
|
-
・
|
126
|
-
・
|
127
|
-
"invocation": {
|
128
|
-
"module_args": {
|
129
|
-
"checksum_algorithm": "sha1",
|
130
|
-
・
|
131
|
-
・
|
132
|
-
"get_mime": true,
|
133
|
-
"path": "/home/hoge_hoge/hoge1.log"
|
134
|
-
}
|
135
|
-
},
|
136
|
-
"item": "hoge1.log",
|
137
|
-
"stat": {
|
138
|
-
"atime": 1110609251.1956754,
|
139
|
-
"attr_flags": "e",
|
140
|
-
"attributes": [
|
141
|
-
"extents"
|
142
|
-
], ・
|
143
|
-
・
|
144
|
-
"block_size": 4096,
|
145
|
-
"blocks": 8,
|
121
|
+
# 下記の「Check hoge_web.logタスクのitemに渡される一覧の抜粋」が次々と渡されている様子
|
122
|
+
ok: [localhost] => (item=[{'invocation': {'module_args': {'checksum_algorithm': 'sha1', 'get_checksum': True, 'follow': False, 'path': '/home/hoge_hoge/hoge1.log', 'get_md5': False, 'get_mime': True, 'get_attributes': True}}, 'stat': {'charset': 'binary', 'uid': 0, 'exists': True, 'attr_flags': 'e', 'woth': False, 'isreg': True, 'device_type': 0, 'mtime': 1710652113.4640188, 'block_size': 4096, 'inode': 2416182, 'isgid': False, 'size': 1219, 'executable': False, 'roth': True, 'isuid': False, 'readable': True, 'version': '1282907058', 'pw_name': 'root', 'gid': 0, 'ischr': False, 'wusr': True, 'writeable': True, 'isdir': False, 'blocks': 8, 'xoth': False, 'rusr': True, 'nlink': 1, 'issock': False, 'rgrp': True, 'gr_name': 'root', 'path': '/home/hoge_hoge/hoge1.log', 'xusr': False, 'atime': 1710627251.1956754, 'mimetype': 'application/octet-stream', 'ctime': 1710652113.4640188, 'isblk': False, 'checksum': '4・・1b55・・・49a3d・・', 'dev': 64513, 'wgrp': False, 'isfifo': False, 'mode': '0644', 'xgrp': False, 'islnk': False, 'attributes': ['extents']}, 'changed': False, 'failed': False, 'item': 'saveMessage.log', 'ansible_loop_var': 'item'}, {'invocation': {'module_args': {'checksum_algorithm': 'sha1', 'get_checksum': True, 'follow': False, 'path': '/home/hmiyamot/hs_lsg_hsl/getMessage.log', 'get_md5': False, 'get_mime': True, 'get_attributes': True}}, 'stat': {'charset': 'us-ascii', 'uid': 0, 'exists': True, 'attr_flags': 'e', 'woth': False, 'isreg': True, 'device_type': 0, 'mtime': 1710652114.3400238, 'block_size': 4096, 'inode': 2416199, 'isgid': False, 'size': 1189, 'executable': False, 'roth': True, 'isuid': False, 'readable': True, 'version': '1282907076', 'pw_name': 'root', 'gid': 0, 'ischr': False, 'wusr': True, 'writeable': True, 'isdir': False, 'blocks': 8, 'xoth': False, 'rusr': True, 'nlink': 1, 'issock': False, 'rgrp': True, 'gr_name': 'root', 'path': '/home/hoge_hoge/hoge2.log', 'xusr': False, 'atime': 1710627252.0996804, 'mimetype': 'text/plain', 'ctime': 1710652114.3400238, 'isblk': False, 'checksum': '960b・・・deb55337b07', 'dev': 64513, 'wgrp': False, 'isfifo': False, 'mode': '0644', 'xgrp': False, 'islnk': False, 'attributes': ['extents']}, 'changed': False, 'failed': False, 'item': 'hoge2.log', 'ansible_loop_var': 'item'}])
|
123
|
+
```
|
146
124
|
|
147
|
-
"executable": false,
|
148
|
-
"exists": true,
|
149
|
-
・
|
150
|
-
・
|
151
|
-
"path": "/home/hoge_hoge/hoge1.log",
|
152
|
-
"pw_name": "root",
|
153
|
-
"readable": true,
|
154
|
-
・
|
155
|
-
・
|
156
|
-
```
|
9
該当コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -110,14 +110,47 @@
|
|
110
110
|
ansible.builtin.file:
|
111
111
|
path: "{{ task_dir }}/hoge_hoge/{{ item }}"
|
112
112
|
state: absent
|
113
|
-
register: check_loop
|
113
|
+
register: check_loop ・
|
114
|
+
・
|
114
115
|
loop:
|
115
116
|
- "hoge_check.results"
|
116
117
|
when:
|
117
118
|
```
|
118
|
-
|
119
|
+
### Check hoge_web.logのitemに渡される一覧の抜粋
|
119
120
|
```
|
120
|
-
|
121
|
+
"hoge_check.results": [
|
122
|
+
{ ・
|
123
|
+
・
|
124
|
+
"ansible_loop_var": "item",
|
125
|
+
・
|
126
|
+
・
|
121
|
-
a
|
127
|
+
"invocation": {
|
128
|
+
"module_args": {
|
129
|
+
"checksum_algorithm": "sha1",
|
130
|
+
・
|
131
|
+
・
|
132
|
+
"get_mime": true,
|
133
|
+
"path": "/home/hoge_hoge/hoge1.log"
|
134
|
+
}
|
122
|
-
|
135
|
+
},
|
136
|
+
"item": "hoge1.log",
|
137
|
+
"stat": {
|
138
|
+
"atime": 1110609251.1956754,
|
139
|
+
"attr_flags": "e",
|
140
|
+
"attributes": [
|
141
|
+
"extents"
|
142
|
+
], ・
|
143
|
+
・
|
144
|
+
"block_size": 4096,
|
145
|
+
"blocks": 8,
|
123
146
|
|
147
|
+
"executable": false,
|
148
|
+
"exists": true,
|
149
|
+
・
|
150
|
+
・
|
151
|
+
"path": "/home/hoge_hoge/hoge1.log",
|
152
|
+
"pw_name": "root",
|
153
|
+
"readable": true,
|
154
|
+
・
|
155
|
+
・
|
156
|
+
```
|
8
該当コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -106,12 +106,18 @@
|
|
106
106
|
- "hoge1.log"
|
107
107
|
- "hoge2.log"
|
108
108
|
|
109
|
-
- name: Delete
|
109
|
+
- name: Delete hoge_web.log
|
110
110
|
ansible.builtin.file:
|
111
111
|
path: "{{ task_dir }}/hoge_hoge/{{ item }}"
|
112
112
|
state: absent
|
113
|
+
register: check_loop
|
113
114
|
loop:
|
114
115
|
- "hoge_check.results"
|
115
116
|
when:
|
116
117
|
```
|
118
|
+
結果
|
119
|
+
```
|
120
|
+
# check_loopの結果
|
121
|
+
ansible.builtin.debug:
|
122
|
+
var:
|
117
123
|
|
7
該当のソースコードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -97,7 +97,7 @@
|
|
97
97
|
}
|
98
98
|
```
|
99
99
|
④
|
100
|
-
```
|
100
|
+
```hoge.yml
|
101
101
|
- name: Check hoge_web.log
|
102
102
|
ansible.builtin.stat:
|
103
103
|
path: "{{ task_dir }}/hoge_hoge/{{ item }}"
|
6
該当のソースコードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -96,3 +96,22 @@
|
|
96
96
|
"msg": "list"
|
97
97
|
}
|
98
98
|
```
|
99
|
+
④
|
100
|
+
```
|
101
|
+
- name: Check hoge_web.log
|
102
|
+
ansible.builtin.stat:
|
103
|
+
path: "{{ task_dir }}/hoge_hoge/{{ item }}"
|
104
|
+
register: hoge_check
|
105
|
+
loop:
|
106
|
+
- "hoge1.log"
|
107
|
+
- "hoge2.log"
|
108
|
+
|
109
|
+
- name: Delete hoge_web.log
|
110
|
+
ansible.builtin.file:
|
111
|
+
path: "{{ task_dir }}/hoge_hoge/{{ item }}"
|
112
|
+
state: absent
|
113
|
+
loop:
|
114
|
+
- "hoge_check.results"
|
115
|
+
when:
|
116
|
+
```
|
117
|
+
|
5
説明文の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,8 +18,8 @@
|
|
18
18
|
変数(hoge_check)を確認すると③の結果となっており、変数(hoge_check.results)はlist型であるため、stat.existsによるtrue/falseが確認出来ません。
|
19
19
|
1タスク内で複数のファイルの有無をチェックして、存在する場合に削除する方法はありますでしょうか。
|
20
20
|
|
21
|
-
fileモジュールのstateにabsentを設定すればファイルが無い場合には何もしないので
|
21
|
+
fileモジュールのstateにabsentを設定すればファイルが無い場合には何もしないので
|
22
|
-
どのようにすれば有無チェック出来るのか
|
22
|
+
有無チェックは本来不要ですが、どのようにすれば有無チェック出来るのか知りたいです。
|
23
23
|
|
24
24
|
### 発生している問題・エラーメッセージ
|
25
25
|
|
4
説明文の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -17,6 +17,9 @@
|
|
17
17
|
となり値が存在しない結果となります。
|
18
18
|
変数(hoge_check)を確認すると③の結果となっており、変数(hoge_check.results)はlist型であるため、stat.existsによるtrue/falseが確認出来ません。
|
19
19
|
1タスク内で複数のファイルの有無をチェックして、存在する場合に削除する方法はありますでしょうか。
|
20
|
+
|
21
|
+
fileモジュールのstateにabsentを設定すればファイルが無い場合には何もしないので有無チェックは本来不要ですが
|
22
|
+
どのようにすれば有無チェック出来るのか調べています。
|
20
23
|
|
21
24
|
### 発生している問題・エラーメッセージ
|
22
25
|
|
3
説明文の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
### 該当のソースコード
|
28
28
|
```
|
29
|
-
# 本来は下記のように複数ファイルの有無を同時にチェックして存在する場合は削除したい
|
29
|
+
# 本来は下記のように複数ファイルの有無を同時にチェックして複数存在する場合は同時に削除したい
|
30
30
|
- name: Check hoge_web.log
|
31
31
|
ansible.builtin.stat:
|
32
32
|
path: "{{ task_dir }}/hoge_hoge/{{ item }}"
|
2
説明文の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -25,6 +25,24 @@
|
|
25
25
|
```
|
26
26
|
|
27
27
|
### 該当のソースコード
|
28
|
+
```
|
29
|
+
# 本来は下記のように複数ファイルの有無を同時にチェックして存在する場合は削除したい
|
30
|
+
- name: Check hoge_web.log
|
31
|
+
ansible.builtin.stat:
|
32
|
+
path: "{{ task_dir }}/hoge_hoge/{{ item }}"
|
33
|
+
register: hoge_check
|
34
|
+
loop:
|
35
|
+
- "hoge1.log"
|
36
|
+
- "hoge2.log"
|
37
|
+
- name: Delete hoge_web.log
|
38
|
+
ansible.builtin.file:
|
39
|
+
path: "{{ task_dir }}/hoge_hoge/{{ item }}"
|
40
|
+
state: absent
|
41
|
+
loop:
|
42
|
+
- "hoge1.log"
|
43
|
+
- "hoge2.log"
|
44
|
+
when: hoge_check.stat.exists
|
45
|
+
```
|
28
46
|
①
|
29
47
|
```/hoge/hoge1.yml
|
30
48
|
- name: Check hoge_web.log
|
@@ -34,15 +52,8 @@
|
|
34
52
|
- name: Result hoge_web.log
|
35
53
|
ansible.builtin.debug:
|
36
54
|
var: hoge_check.stat.exists
|
37
|
-
- name: Delete hoge_web.log
|
38
|
-
ansible.builtin.file:
|
39
|
-
path: "{{ task_dir }}/hoge_hoge/{{ item }}"
|
40
|
-
state: absent
|
41
|
-
loop:
|
42
|
-
- "hoge1.log"
|
43
|
-
- "hoge2.log"
|
44
|
-
when: hoge_check.stat.exists
|
45
55
|
```
|
56
|
+
|
46
57
|
結果
|
47
58
|
```
|
48
59
|
# var: hoge_check.stat.exists
|
1
説明文の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
### 実現したいこと
|
2
2
|
|
3
3
|
statモジュールで対象ファイルの有無確認を行い、変数(stat.exists)の結果がtrueの場合に
|
4
|
-
ファイルを削除をしたいです。
|
4
|
+
①のタスクにて複数のファイルを同時に削除をしたいです。
|
5
5
|
対象ファイルは複数あるため、loopやwith_itemsを使って1タスク内で複数のファイルの有無を
|
6
6
|
同時にチェックして存在するファイルは削除したいです。
|
7
7
|
|
@@ -34,6 +34,14 @@
|
|
34
34
|
- name: Result hoge_web.log
|
35
35
|
ansible.builtin.debug:
|
36
36
|
var: hoge_check.stat.exists
|
37
|
+
- name: Delete hoge_web.log
|
38
|
+
ansible.builtin.file:
|
39
|
+
path: "{{ task_dir }}/hoge_hoge/{{ item }}"
|
40
|
+
state: absent
|
41
|
+
loop:
|
42
|
+
- "hoge1.log"
|
43
|
+
- "hoge2.log"
|
44
|
+
when: hoge_check.stat.exists
|
37
45
|
```
|
38
46
|
結果
|
39
47
|
```
|