質問編集履歴

1

提案内容に対して追記

2017/06/30 06:54

投稿

hotta
hotta

スコア1613

test CHANGED
File without changes
test CHANGED
@@ -109,3 +109,55 @@
109
109
  そもそも、shell ディレクティブはセキュリティ上あまり推奨されないようです。
110
110
 
111
111
  なにかもっとすっきりした解決方法があればご教示願います。
112
+
113
+
114
+
115
+ 【追記】
116
+
117
+
118
+
119
+ 「yumモジュールのlist」 は、存在だけは知っていたのですが、使い方が
120
+
121
+ 今ひとつよくわかりません。今回のケースだと、以下のように書けば、一応
122
+
123
+ 通りはするようです。
124
+
125
+
126
+
127
+ ```bash
128
+
129
+ $ cat test3.yml
130
+
131
+ ---
132
+
133
+ - hosts: localhost
134
+
135
+ tasks:
136
+
137
+ - yum:
138
+
139
+ list: postgresql-libs
140
+
141
+ register: default_pkg
142
+
143
+ # - debug: var=default_pkg
144
+
145
+ - yum:
146
+
147
+ name: postgresql-libs
148
+
149
+ state: absent
150
+
151
+ when: (default_pkg.results[0].name == 'postgresql-libs' and default_pkg.results[0].yumstate == 'installed') or
152
+
153
+ (default_pkg.results[1].name == 'postgresql-libs' and default_pkg.results[1].yumstate == 'installed') or
154
+
155
+ (default_pkg.results[2].name == 'postgresql-libs' and default_pkg.results[2].yumstate == 'installed')
156
+
157
+ ```
158
+
159
+
160
+
161
+ ただ、一般に yum list で候補が何個出てくるのかは不定なので、ここでは
162
+
163
+ 3個と決め打ちになってしまっています。どう書くのが正解でしょうか?