本地读取文件并在Ansible中使用vars remote

本地读取文件并在Ansible中使用vars remote,ansible,Ansible,我在本地阅读了一个YAML文件,其中包含以下剧本: - name: Ensure the deploy_manifest var is defined and read deploy manifest hosts: localhost connection: local gather_facts: False tasks: - assert: that: deploy_manifest is defined msg: |

我在本地阅读了一个YAML文件,其中包含以下剧本:

- name: Ensure the deploy_manifest var is defined and read deploy manifest
  hosts: localhost
  connection: local
  gather_facts: False
  tasks:
    - assert:
        that: deploy_manifest is defined
        msg: |
          Error: Must provide providers config path. Fix: Add '-e deploy_manifest=/path/to/manifest' to the ansible-playbook command

    - name: Read deploy manifest
      include_vars:
        file: "{{ deploy_manifest }}"
        name: manifest
      register: manifest

    - debug:
        msg: "[{{ manifest.key }}]: {{ manifest.value }}"
      with_dict: "{{ manifest.ansible_facts }}"
然后在我运行的同一个剧本YAML文件中:

- name: Deploy Backend services
  hosts: backend
  remote_user: ubuntu
  gather_facts: False
  vars:
    env: "{{ env }}"
    services: "{{ manifest.ansible_facts }}"
  tasks:
    - include_role:
        name: services_backend
      when: backend | default(true) | bool
但是,由于调试失败,它无法工作。它说清单是空的

读取一个YAML文件或一个playbook中的配置,然后将变量传递到另一个playbook中的最佳方法是什么?

您的调试模块没有说manifest为空,而是说key manifest.key不存在,因为它不存在

您已将名为manifest的事实注册到:

您尝试引用上述清单中名为key的key和另一个key!命名值:

请阅读第章,并确认在不使用的情况下,您指的是使用项的迭代变量

请注意,使用name:manifest和register:manifest,您将vars文件读入manifest.ansible\u facts.manifest

请遵循并回答您随后的问题,使其至少对其他人具有最低价值。 ・ 您在使用错误的变量名时犯了一个错误,但您的问题是:读取YAML文件或通常在playbook中的配置,然后将变量传递到另一个playbook中的最佳方法是什么?ー 这不是一个活跃了6年以上的用户应该发布的内容。标题在本地读取文件并在Ansible中使用vars remote是一个超现实主义的例子,而不是工程。
register: manifest
msg: "[{{ manifest.key }}]: {{ manifest.value }}"