0

我有自动化的 ansible playbook 来生成在文件夹中创建 AWS 资源所需的 Terraform 文件。生成文件后,ansible 任务运行 terraform 计划(使用以下计划代码),但失败并出现以下错误(错误)

Ansible 版本:

ansible [core 2.11.2] 
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible

地形版本: Terraform v0.12.31

计划代码:

- name: Create Terraform plan
  check_mode: true
  community.general.terraform:
    project_path: "{{ terraform_dir }}"
    plan_file: "{{ terraform_dir }}/tfplan"
    state: "planned"
    force_init: true
  register: plan
  tags:
    - build
    - plan
    - never

错误:

**fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):
  File \"/root/.ansible/tmp/ansible-tmp-1625160772.6764412-713-181137940992596/AnsiballZ_terraform.py\", line 100, in <module>
    _ansiballz_main()
  File \"/root/.ansible/tmp/ansible-tmp-1625160772.6764412-713-181137940992596/AnsiballZ_terraform.py\", line 92, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File \"/root/.ansible/tmp/ansible-tmp-1625160772.6764412-713-181137940992596/AnsiballZ_terraform.py\", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.terraform', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.terraform', _modlib_path=modlib_path),
  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code
    exec(code, run_globals)
  File \"/tmp/ansible_community.general.terraform_payload_xnzkbjkr/ansible_community.general.terraform_payload.zip/ansible_collections/community/general/plugins/modules/terraform.py\", line 497, in <module>
  File \"/tmp/ansible_community.general.terraform_payload_xnzkbjkr/ansible_community.general.terraform_payload.zip/ansible_collections/community/general/plugins/modules/terraform.py\", line 393, in main
  File \"/tmp/ansible_community.general.terraform_payload_xnzkbjkr/ansible_community.general.terraform_payload.zip/ansible_collections/community/general/plugins/modules/terraform.py\", line 238, in get_version
  File \"/usr/lib/python3.8/json/__init__.py\", line 357, in loads
    return _default_decoder.decode(s)
  File \"/usr/lib/python3.8/json/decoder.py\", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File \"/usr/lib/python3.8/json/decoder.py\", line 355, in raw_decode
    raise JSONDecodeError(\"Expecting value\", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
", "module_stdout": "", "msg": "MODULE FAILURE
See stdout/stderr for the exact error", "rc": 1}**

不确定我是否错过了安装任何必需的模块,或者我是否需要更改代码。知道如何解决上述错误吗?

如果需要任何进一步的信息,请告诉我。

提前致谢。

4

1 回答 1

1

通过更改 ansible-galaxy collection 版本修复了上述错误(ansible-galaxy collection install community.general:1.3.9)。

导致上述错误的 ansible-galaxy 版本大于1.3.9 ,因为大于 1.3.9 的版本与 terraform 版本v0.12.31不兼容

以前我安装了 ansible-galaxy 集合版本 2.2.0,将版本降级到 1.3.9 解决了我的问题。

于 2021-07-07T03:15:18.833 回答