Spec-Zone.ru › Ansible 2.11

ansible.utils.fact_diff – Найти разницу между текущими фактами

Примечание

Этот плагин входит в состав коллекции ansible.utils (версия 2.0.0).

Для его установки используйте: ansible-galaxy collection install ansible.utils.

Для использования в книге задач укажите: ansible.utils.fact_diff.

Новое в версии 1.0.0: of ansible.utils

  • Описание
  • Параметры
  • Примеры
  • Возвращаемые значения

Описание

  • Сравнение двух фактов или переменных и получение разницы.

Примечание

У этого модуля есть соответствующий плагин действий.

Параметры

Параметр Варианты/Значения по умолчанию Комментарии
after
raw / required
Второй факт для сравнения.
before
raw / required
Первый факт для сравнения.
plugin
словарь
Значение по умолчанию:
{}
Настройка и указание плагина diff для использования
name
строка
Значение по умолчанию:
"ansible.utils.native"
Плагин diff для использования в формате полного имени коллекции.
vars
словарь
Значение по умолчанию:
{}
Параметры, передаваемые плагину diff.
skip_lines
список / элементы=строка
Пропустить строки, соответствующие этим регулярным выражениям.
Совпадения будут удалены до дифференцирования.
Если предоставленные before и after являются строками, они будут разделены.
Каждый элемент в каждом списке будет преобразован в строку для сравнения.

Примеры

- ansible.builtin.set_fact:
    before:
      a:
        b:
          c:
            d:
            - 0
            - 1
    after:
      a:
        b:
          c:
            d:
            - 2
            - 3

- name: Show the difference in json format
  ansible.utils.fact_diff:
    before: "{{ before }}"
    after: "{{ after }}"

# TASK [ansible.utils.fact_diff] **************************************
# --- before
# +++ after
# @@ -3,8 +3,8 @@
#          "b": {
#              "c": {
#                  "d": [
# -                    0,
# -                    1
# +                    2,
# +                    3
#                  ]
#              }
#          }
#
# changed: [localhost]

- name: Show the difference in path format
  ansible.utils.fact_diff:
    before: "{{ before|ansible.utils.to_paths }}"
    after: "{{ after|ansible.utils.to_paths }}"

# TASK [ansible.utils.fact_diff] **************************************
# --- before
# +++ after
# @@ -1,4 +1,4 @@
#  {
# -    "a.b.c.d[0]": 0,
# -    "a.b.c.d[1]": 1
# +    "a.b.c.d[0]": 2,
# +    "a.b.c.d[1]": 3
#  }
#
# changed: [localhost]

- name: Show the difference in yaml format
  ansible.utils.fact_diff:
    before: "{{ before|to_nice_yaml }}"
    after: "{{ after|to_nice_yaml }}"

# TASK [ansible.utils.fact_diff] **************************************
# --- before
# +++ after
# @@ -2,5 +2,5 @@
#      b:
#          c:
#              d:
# -            - 0
# -            - 1
# +            - 2
# +            - 3

# changed: [localhost]


#### Show the difference between complex object using restconf
#  ansible_connection: ansible.netcommon.httpapi
#  ansible_httpapi_use_ssl: True
#  ansible_httpapi_validate_certs: False
#  ansible_network_os: ansible.netcommon.restconf

- name: Get the current interface config prior to changes
  ansible.netcommon.restconf_get:
    content: config
    path: /data/Cisco-NX-OS-device:System/intf-items/phys-items
  register: pre

- name: Update the description of eth1/100
  ansible.utils.update_fact:
    updates:
    - path: "pre['response']['phys-items']['PhysIf-list'][{{ index }}]['descr']"
      value: "Configured by ansible {{ 100 | random }}"
  vars:
    index: "{{ pre['response']['phys-items']['PhysIf-list']|ansible.utils.index_of('eq', 'eth1/100', 'id') }}"
  register: updated

- name: Apply the configuration
  ansible.netcommon.restconf_config:
    path: 'data/Cisco-NX-OS-device:System/intf-items/'
    content: "{{ updated.pre.response}}"
    method: patch

- name: Get the current interface config after changes
  ansible.netcommon.restconf_get:
    content: config
    path: /data/Cisco-NX-OS-device:System/intf-items/phys-items
  register: post

- name: Show the difference
  ansible.utils.fact_diff:
    before: "{{ pre.response|ansible.utils.to_paths }}"
    after: "{{ post.response|ansible.utils.to_paths }}"

# TASK [ansible.utils.fact_diff] *********************************************
# --- before
# +++ after
# @@ -3604,7 +3604,7 @@
#      "phys-items['PhysIf-list'][37].bw": "0",
#      "phys-items['PhysIf-list'][37].controllerId": "",
#      "phys-items['PhysIf-list'][37].delay": "1",
# -    "phys-items['PhysIf-list'][37].descr": "Configured by ansible 95",
# +    "phys-items['PhysIf-list'][37].descr": "Configured by ansible 20",
#      "phys-items['PhysIf-list'][37].dot1qEtherType": "0x8100",
#      "phys-items['PhysIf-list'][37].duplex": "auto",
#      "phys-items['PhysIf-list'][37].id": "eth1/100",

# changed: [nxos101]

Возвращаемые значения

Общие возвращаемые значения документированы здесь, следующие являются полями, уникальными для этого модуля:

Ключ Возвращаемое значение Описание
diff_lines
список / элементы=строка
всегда
Строки diff_text, разделенные по строкам.

diff_text
строка
всегда
Разница в текстовом формате.



Авторы

  • Bradley Thornton (@cidrblock)

© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.11/collections/ansible/utils/fact_diff_module.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API