【发布时间】:2021-07-17 04:28:13
【问题描述】:
我有一本剧本,我收到一条错误消息
fatal: [localhost]: FAILED! => {"ansible_facts": {"tasks": {}}, "ansible_included_var_files": [], "changed": false, "message": "/home/user/invoke_api/automation/tmp/task.yml must be stored as a dictionary/hash"}
task.yml
task.yml 文件是动态创建的,并一直从其他来源过滤以提供以下输出。
- key: gTest101
value:
Comments: FWP - Testing this
IP: 10.1.2.3
Name: gTest101
- key: gTest102
value:
Comments: FWP - Applying this
IP: 10.1.2.4
Name: gTest102
问题:如何将 task.yml 中的列表转换为字典?从列表转换为字典的代码是什么
playbook.yml
---
- name: Global Objects
hosts: check_point
connection: httpapi
gather_facts: False
vars_files:
- 'credentials/my_var.yml'
- 'credentials/login.yml'
tasks:
- name: read-new-tmp-file
include_vars:
file: tmp/task.yml
name: tasks
register: new_host
- name: add-host-object-to-group
check_point.mgmt.cp_mgmt_host:
name: "{{ item.value.Name | quote }}"
ip_address: "{{ item.value.IP | quote }}"
comments: "{{ item.value.Comments }}"
groups: gTest1A
state: present
auto_publish_session: yes
loop: "{{ new_host.dict | dict2items }}"
delegate_to: Global
ignore_errors: yes
Ansible 核心 2.9.13 python版本= 2.7.17
【问题讨论】:
-
你的播放内容是什么?您的 task.yaml 是 var 文件还是 ansible 任务文件?你的剧本核心是什么?可靠的版本?我们如何重现该错误以帮助您?
-
@idrissEliguene 我已经更新了剧本。 Ansible 核心 2.9.13 python 版本 = 2.7.17
-
@idrissEliguene 这是 task.yml。它是动态创建的,我无法将任何变量添加到文件“task.yml”
- key: gTest101 value: Comments: FWP - Testing this IP: 10.1.2.3 Name: gTest101 - key: gTest102 value: Comments: FWP - Applying this IP: 10.1.2.4 Name: gTest102
标签: list dictionary ansible yaml jinja2