引き続きWindowsUpdateをやってみたお話を書きます。

Ansible関連の実践記事一覧はこちら。

Ansible自動化の実践記事一覧 - てんこ


目的

  • win_updateモジュールの理解度を上げる
    • カテゴリとか
    • log_pathとか
  • win_updateモジュールの公式ドキュメントリンク

ansible.windows.win_updates module – Download and install Windows updates — Ansible Documentation

カテゴリとか

昨日書いてたのは公式ドキュメントのモジュールそのままなんですが、ログを見てたら「installedになってないやつあるな」というのに気が付きました。 実施されていない理由が **"filtered_reason": "category_names"**とかになってました。 おや?と思ってよく読んだら、もっといっぱいカテゴリあるそうで… 指定できるのはこのあたりのようです。 4種類しか確認できていないので、確認できるか、覚えていたら追記します。 たぶん、他のホームページにいろいろと書いてある予感もします。

カテゴリの宣言名Default役割
Application×
Connectors×
Critical Updates○クリティカルパッチ
Definition Updates×Windows Defenderの定義の更新
Developer Kits×
Feature Packs×
Guidance×
Security Updates○セキュリティパッチ
Service Packs×
Tools×
Update Rollups○ロールアップ更新プログラム?
Updates×オプションの更新プログラム?

カテゴリの宣言名の間にある空白は、あってもなくても認識してくれるみたいでした。

ただ、Definition Updatesを試したとき、installed: true とはなっていたものの、reboot_require: falseになっていたのですが、Windows側の画面を見たところ、「今すぐインストールする」ボタンが出ている状態でした。

↓こんなかんじ。 なので、自動では再起動はされず。 その後、手動で再起動してみたら、反映自体はされた模様です。 つぶやいてみたら、つよつよな方からアドバイスが。 あるあるなんだそうです。

WSUSの画面からの追記

なるほど。いくつかは一致しそうだけど、完全一致にはならないな…うーむ。

log_pathとか

モジュールの説明の中で、Windows Updateのログを出力してくれる、という内容が記載されていました。

WindowsUpdate対象のホスト上にログを作ってくれるようなので、win_fileモジュールを使って事前にパスを作る形にして、そこにファイルを作るように指定してみました。

    - name : file creation
      win_file :
        path : C:\Temp
        state : directory
    - name : Run Windows Update
      win_updates :
        category_names :
        - Critical Updates
        - Security Updates
        - Update Rollups
        - Updates
        - Feature Packs
        - Definition Updates
        state : installed
        log_path : C:\Temp\ansible_win_update.log
(後略)

結果、確かにしっかりWindowsUpdateに関するログが出力されていました。

Windows側のログ

2019-10-15 20:59:04Z Creating downloader object...
2019-10-15 20:59:04Z Creating download collection...
2019-10-15 20:59:04Z Adding update (66 of 67) 0025cccd-6122-483a-a646-dd3ea3ff861f
2019-10-15 20:59:04Z Downloading (66 of 67) 0025cccd-6122-483a-a646-dd3ea3ff861f
2019-10-15 20:59:22Z Download result code for (66 of 67) 0025cccd-6122-483a-a646-dd3ea3ff861f = 2
(略)
2019-10-15 20:59:28Z Adding update 0025cccd-6122-483a-a646-dd3ea3ff861f
(略)
2019-10-15 21:02:03Z Update (66 of 67) 0025cccd-6122-483a-a646-dd3ea3ff861f succeeded
(略)
2019-10-15 21:02:03Z Performing post-install reboot requirement check...
2019-10-15 21:02:03Z Return value:
{
    "updates":  {
(略)
                    "0025cccd-6122-483a-a646-dd3ea3ff861f":  {
                                                                 "id":  "0025cccd-6122-483a-a646-dd3ea3ff861f",
                                                                 "title":  "Windows Server 2012 R2 用更新プログラム (KB3179574)",
                                                                 "categories":  [
                                                                                    "Updates",
                                                                                    "Windows Server 2012 R2"
                                                                                ],
                                                                 "kb":  [
                                                                            "3179574"
                                                                        ],
                                                                 "installed":  true
                                                             },
(略)
}
2019-10-15 21:02:03Z Native job completed with output:
Name                           Value
----                           -----
updates                        {dc8db314-00e0-4fda-9996-8e5baf354720, 443e9449-d923-489b-9e77-39a51056fe0e, 7c295ac6-6cb2-4d47-821b-74b584a6d53e, 2079038a-206c-40c1-94a0-68c9c51ea6fb...}
failed_update_count            0
found_update_count             67
changed                        True
reboot_required                True
installed_update_count         67
filtered_updates               {5aa5521c-0343-48a0-bba4-d2a5b9357e81}

なるほどー。と思った反面、これってモジュール実施中はそのPlaybookからは参照指定とかできないので、やるとしても別でPlaybookで参照用・抽出用を走らせないといけないのかなと思い、そこまでするもんでもないあかなあという思いに至りました。


https://tenko.hatenablog.jp/entry/2019/10/15/224311

バックアップ日時: 2026年11月11日