代码之家  ›  专栏  ›  技术社区  ›  RamenCoder

易出错的剧本外壳模块不工作

  •  0
  • RamenCoder  · 技术社区  · 1 年前

    我建立了一个新的Ansible项目,我想在其中连接到我的EC2机器并运行一些命令。

    我添加了清单文件,当我测试一个简单的Ansible命令时,一切都很好,我得到了响应。

    ansible all -m shell -a 'uptime' ansible all -m ping 工作良好,并返回预期输出。

    然而,当我试图运行一个使用内置shell模块的简单剧本时,它失败了。

    可靠的剧本命令: ansible-playbook -vvv playbooks/my_playbook.yaml 行动手册文件:

    ---
    - hosts: all
      become: yes
      gather_facts: yes
      tasks:
        -   name: Gather EC2 facts
            action: ec2_facts
    - hosts: all
      become: yes
      tasks:
        -   name: my task
            shell: uptime
    

    收集EC2事实运行良好,但运行shell命令的第二部分失败,出现以下异常:

    <1.2.3.4> Failed to connect to the host via ssh: 
    fatal: [1.2.3.4]: FAILED! => {
        "changed": false
    }
    
    MSG:
    
    This module has been removed. The module documentation for Ansible-2.6 may contain hints for porting
    

    我不明白为什么会出现这个异常,因为shell模块从未被弃用过。 我也不使用Ansible-2.6,我通过pip安装了Ansible,版本:

    ansible==2.9.27
    ansible-core==2.15.8
    

    我试图更改为命令模块,这导致了同样的异常,所以我怀疑它必须对我的本地环境而不是shell模块本身进行处理。

    如有任何帮助,我们将不胜感激。

    1 回复  |  直到 1 年前
        1
  •  1
  •   Alexander Pletnev    1 年前

    你在打电话 ec2_facts 作为一个模块 deprecated and then removed in Ansible 2.7 (但他们没有在文档中列出)。尝试使用 ec2_metadata_facts 相反