【问题标题】:Ansible requires python-apt but it's already installedAnsible 需要 python-apt 但它已经安装
【发布时间】:2019-01-08 09:37:19
【问题描述】:

序言:我只是在ansible中迈出第一步,请耐心等待

另外:我在'Ansible demands installing MySQL-python despite it was already installed' 阅读了答案,但我的情况不同,因为在本地,在控制机器上,一切都是完美的;感谢这个问题,我发现我的问题出在遥控机器上。所以我的问题是一样的,但链接的问题不包含解决我的问题的答案

我正在从命令行测试 ansible。比如我可以ping通

~/.ssh$ ansible openvpn -C -m "ping"
192.168.1.225 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

我尝试启动apt update

我不确定这是否是具有 apt-get update 等价物的正确语法,但这 不是问题

我正在使用-C 来查看当我要求进行试运行时 ansible 对我说了什么。

$ ansible openvpn -C -m "apt update-cache=yes"
192.168.1.225 | FAILED! => {
    "changed": false,
    "msg": "python-apt must be installed to use check mode. If run normally this module can auto-install it."
}

编辑:正如@Davide Maze 所建议的,这可能是由于缺少python-apt。所以我查了一下,但_我有python-apt

$ python -V
Python 2.7.15rc1

$ pip list
... cut ...
python-apt (1.6.2)
... cut ...

$ which python
/usr/bin/python

我的问题是:为什么 ansible 告诉我没有安装 python-apt,以及如何解决这个问题?

【问题讨论】:

    标签: python ansible


    【解决方案1】:

    感谢@David Maze 为我指明了正确的方向

    我在 controller 机器中检查 python-apt,而不是在 受控 机器中。

    所以我将包从 controller 安装到 受控 机器中,使用:

    $ ansible openvpn -m "apt name=python-apt state=latest" --become-user realtebo
    

    您也可以使用以下表格,即sudo apt-get update 并等待操作员输入密码。用户是通过 ssh 登录的用户;所以检查你的配置。就我而言,我使用的是 ssh 密钥;密码登录完全被禁用。

    $ ansible openvpn -m apt -a "update-cache=yes" --become --ask-become-pass
    

    提示 1:为了避免这种交互,可以使用保险库,但我还没有尝试过。

    提示 2:另外,--ask-become-pass 不在您可能正在寻找的文档中,在信 a;这是因为选项在-K中被缩短,大写,所以向下看See the doc

    确保远程包python-apt 可用后,-C 选项开始起作用,正是因为现在python-apt 远程可用。

    ansible openvpn -C -m "apt name=python state=latest"
    
    192.168.1.225 | SUCCESS => {
        "cache_update_time": 1533077635,
        "cache_updated": false,
        "changed": false
    }
    

    【讨论】:

      【解决方案2】:

      我在运行ansible-playbook 时使用ansible_python_interpreter 参数解决了这个错误,如下所示。

      ansible-playbook playbook_name.yml -e ansible_python_interpreter=/usr/bin/python --check

      【讨论】:

        猜你喜欢
        • 2021-11-11
        • 2016-02-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-13
        • 1970-01-01
        • 2016-10-02
        • 2021-06-11
        相关资源
        最近更新 更多