ansible.builtin.ini,无效文件名:'无

问题描述 投票:0回答:1

我尝试通过ansible.builtin.ini解析ini文件,但收到错误消息:

"msg": "An unhandled exception occurred while running the lookup plugin 'ansible.builtin.ini'. Error was a <class 'ansible.errors.AnsibleParserError'>, original message: Invalid filename: 'None'"

我的剧本是这样的:

- name: Parse dependency jars
  set_fact:
    common_jars: "{{ lookup('ansible.builtin.ini', 'common-dependency', section='common', file='DEPENDENCY-JARS.ini') }}"
    interface_jars: "{{ lookup('ansible.builtin.ini', 'interface-dependency', section='interface', file='DEPENDENCY-JARS.ini') }}"

DEPENDENCY-JARS.ini 文件与 playbook 文件放在同一路径下,有谁知道为什么它总是抛出上述错误? Ansible 版本是 2.9,谢谢。

ansible
1个回答
0
投票

问:该文件与 playbook 文件位于同一路径。

A:使用特殊变量playbook_dir。例如,给定用于测试的文件

shell> cat DEPENDENCY-JARS.ini 
[common]
common-dependency = foo

[interface]
interface-dependency = bar

这部剧

- hosts: localhost

  vars:

    filename: "{{ playbook_dir }}/DEPENDENCY-JARS.ini"

  tasks:

    - name: Parse dependency jars
      set_fact:
        common_jars: "{{ lookup('ansible.builtin.ini',
                                'common-dependency',
                                section='common',
                                file=filename) }}"
        interf_jars: "{{ lookup('ansible.builtin.ini',
                                'interface-dependency',
                                section='interface',
                                file=filename) }}"

    - debug:
        msg: |
          common_jars: {{ common_jars }}
          interf_jars: {{ interf_jars }}

给出(删节)

  msg: |-
    common_jars: foo
    interf_jars: bar
© www.soinside.com 2019 - 2024. All rights reserved.