ansible.utils.fact_diff モジュールで特定行を無視する。

はじめに

Ansibleでdiffするansible.utils.fact_diffモジュールに、skip_linesという特定行をスキップするためのパラメータがあります。使い方は下記ドキュメントに記載の通りなのですが、ぱっと見わかりづらかったのと、Examplesにサンプルコードがなかったので、自分用のメモに。

docs.ansible.com

Playbook

---
- hosts: localhost
  gather_facts: false
  connection: local
  vars:
    before:
      - google
      - apple
      - facebook
      - amazon
    after:
      - google
      - apple
      - meta
      - amazon
      - '*kigou* to space!'
  tasks:
    - name: diff
      ansible.utils.fact_diff:
        before: "{{ before }}"
        after: "{{ after }}"

    - name: diff skipping the lines
      ansible.utils.fact_diff:
        before: "{{ before }}"
        after: "{{ after }}"
        plugin:
          vars:
            skip_lines:
              - facebook
              - ^m\S.+a$
              - \*kigou\* to space\!

実行結果

PLAY [localhost] *************************************************************************************************************************************************

TASK [diff] ******************************************************************************************************************************************************
--- before
+++ after
@@ -1,4 +1,5 @@
 google
 apple
-facebook
+meta
 amazon
+*kigou* to space!

changed: [localhost]

TASK [diff skipping the lines] ***********************************************************************************************************************************
ok: [localhost]

PLAY RECAP *******************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

以上。