【问题标题】:'Connection' object has no attribute 'ssh' ansible on macOS?'Connection' 对象在 macOS 上没有属性 'ssh' ansible?
【发布时间】:2019-06-25 16:36:14
【问题描述】:

我正在尝试在 ansible playbook 中运行如下任务。

- name: Add user to a group
      user:
        name: "{{ansible_user}}"
        groups: docker
        append: yes
      become: yes
      when: node_type == "peer"

我正在使用 macOS 并且已经安装了 ansible 和 sshpass。我可以在远程 linux 机器上通过 ansible 运行不同的任务,但是当运行这个组任务时,我收到'Connection' object has no attribute 'ssh' ansible 的错误。

请指导我可能是什么问题?

编辑: 追溯问题

ERROR! Unexpected Exception, this is probably a bug: 'Connection' object has no attribute 'ssh'
the full traceback was:

Traceback (most recent call last):
  File "/usr/local/bin/ansible-playbook", line 118, in <module>
    exit_code = cli.run()
  File "/Library/Python/2.7/site-packages/ansible/cli/playbook.py", line 122, in run
    results = pbex.run()
  File "/Library/Python/2.7/site-packages/ansible/executor/playbook_executor.py", line 156, in run
    result = self._tqm.run(play=play)
  File "/Library/Python/2.7/site-packages/ansible/executor/task_queue_manager.py", line 291, in run
    play_return = strategy.run(iterator, play_context)
  File "/Library/Python/2.7/site-packages/ansible/plugins/strategy/linear.py", line 267, in run
    results.extend(self._execute_meta(task, play_context, iterator, host))
  File "/Library/Python/2.7/site-packages/ansible/plugins/strategy/__init__.py", line 1098, in _execute_meta
    connection.reset()
  File "/Library/Python/2.7/site-packages/ansible/plugins/connection/paramiko_ssh.py", line 539, in reset
    self.close()
  File "/Library/Python/2.7/site-packages/ansible/plugins/connection/paramiko_ssh.py", line 606, in close
    self.ssh.close()
AttributeError: 'Connection' object has no attribute 'ssh'

编辑:

我被要求检查ansible.cfg 文件。但我无法在 mac 上找到此文件。

以下是我使用ansible --version 命令时的日志

ansible 2.7.6

config file = None

配置的模块搜索路径 = [u'/Users/dhiraj/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python模块位置= /Library/Python/2.7/site-packages/ansible 可执行位置 = /usr/local/bin/ansible python 版本 = 2.7.10(默认,2017 年 7 月 15 日,17:16:57)[GCC 4.2.1 兼容 Apple LLVM 9.0.0 (clang-900.0.31)]

【问题讨论】:

  • 请帮我们一个忙并发布实际的回溯,因为错误消息只是冰山一角。另外,将来请考虑合理地格式化您的问题,因为 YAML非常关心空格
  • 请检查我更新的问题。我现在添加了回溯。
  • 礼貌地表明你已经提交了一个问题,避免人们转动他们的轮子:github.com/ansible/ansible/issues/51590(也可以试试ansible.cfg change from the comments

标签: macos ssh ansible sshpass


【解决方案1】:

我已经通过步骤解决了问题

使用此链接中的内容创建了一个 .ansible.cfg 文件并将该文件放在我的主目录中,即

/Users/用户名/.ansible.cfg

我在.ansible.cfg文件中添加了

[默认值]

传输 = ssh

我在 ANSIBLE_CONFIG 环境变量中添加了 .ansible.cfg 的路径

我将其导出为 export ANSIBLE _CONFIG=$HOME/.ansible.cfg in .bash_profile

完成所有这些步骤后,我能够运行 playbook。

【讨论】:

    猜你喜欢
    • 2021-09-25
    • 2022-11-27
    • 2023-01-24
    • 2021-11-20
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    相关资源
    最近更新 更多