【问题标题】:How do I share variables/facts between Molecule Playbooks?如何在 Molecule Playbooks 之间共享变量/事实?
【发布时间】:2020-12-19 06:54:18
【问题描述】:

我正在尝试在我的 converge 步骤和我的分子的 cleanup 步骤之间共享一个变量。由于两个剧本都在同一台主机上运行,​​我想我可以使用事实将变量缓存为事实。

converge.yml:

- name: Cache some variable
    set_fact:
      cacheable: yes
      my_fact: "howdy, world"

cleanup.yml:

- debug:
    msg: "{{ my_fact }}"

并在我的顶级ansible.cfg 中指定:

[defaults]
gathering = smart
fact_caching = jsonfile
fact_caching_connection = /tmp/facts_cache
fact_caching_timeout = 7200

我首先运行 molecule converge,然后运行 ​​molecule cleanup 我收到错误:(重新格式化)

TASK [debug] *******************************************************************
fatal: [cluster-toolchain]: FAILED! => {"msg": "The task includes an option
with an undefined variable. The error was: 'my_fact' is undefined
The error appears to be in '{REDACTED}/cleanup.yml': line 5, column 7, but may be
elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:\n\n  tasks:\n    - debug:\n      ^ here\n"}

我有一些猜测,比如 Molecule 可能没有看到我的顶级 ansible.cfg 或其他什么。

无论如何,我希望在这里得到一些帮助。也许有更好的方法来共享分子世界中的变量。

【问题讨论】:

    标签: ansible ansible-facts molecule


    【解决方案1】:

    Molecule 是一个测试 Ansible 角色的工具。它不是针对执行 Ansible 剧本的。通常的命令是ansible-playbook

    Molecule 无法通过事实缓存设置读取您的 ansible.cfg。如果您想让您的命令正常工作,请在molecule.yml 中添加设置:

    provisioner:
      name: ansible
      config_options:
        defaults:
          gathering: smart
          fact_caching: jsonfile
          fact_caching_connection: /tmp/facts_cache
          fact_caching_timeout: 7200
    

    然后molecule converge 后跟molecule cleanup 给出:

    PLAY [Cleanup] ************************************************************************************************************************
    
    TASK [debug] **************************************************************************************************************************
    ok: [vagrant-instance] => {
        "msg": "howdy, world"
    }
    

    【讨论】:

      猜你喜欢
      • 2019-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-27
      • 2017-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多