安塞 bool : APT module: how to get stdout?

标签 ansible aptitude

使用以下答案 stackoverflow.com/questions/34026875/ 我正在尝试从 ansible apt 模块获取标准输出。

使用这个非常简单的测试剧本:

- hosts: localhost
  sudo: true
  tasks:
    - name: 'apt: update & upgrade'
      apt:
        update_cache: yes
        cache_valid_time: 3600
      register: apt
    - debug: msg={{ apt.stdout.split('\n')[:-1] }}

我总是收到此错误消息:

fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stdout'

我尝试了很多方法(安装包、删除......),但总是有相同的错误消息。

使用debug: msg=apt,我可以得到的唯一输出消息是{"cache_update_time": 1531941358, "cache_updated": true, "changed": true} 即使我安装或删除了一个软件包,以我的拙见,这对我来说是一条输出消息,这意味着什么都不清楚,因为 "cache_updated": true, "changed": true 并不意味着软件包已经已安装或删除。

在 Ansible APT 模块文档中 Ansible APT Module Documentation 返回值部分,有一个标准输出返回成功,当需要时

有谁知道如何从 Ansible APT 模块中真正清晰地退出,或者如何强制 Ansible 返回标准输出(ansible 配置,...)以及真正意味着什么“成功,* 需要时* “ 因为我在任何情况下都无法获得标准输出。

亲切的问候

最佳答案

由于此处的文档(“需要时”)不是很清楚,请查看 apt ansible 模块源代码中的 these lines

我的理解:除非命令失败,否则 apt update 的输出将被完全丢弃,在这种情况下,它最终会出现错误消息。

即你最好使用 Michael Ababio's answer

关于安塞 bool : APT module: how to get stdout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51410696/

相关文章:

ubuntu - apt源代码的官方github链接是什么

linux - 哪个shell命令可以找到提供某个完整虚拟包的所有包?

validation - 使用 ansible 的期望变量进行验证

json - 如何解决警告 :The value 4 (type int) in a string field was converted to u'4' (type string) in Ansible?

wordpress - 使 `get_url` 和 `unarchive` ansible 命令幂等

linux - 为什么 aptitude update 会出现 source.list 错误?

shell - Ansible - 当至少一个项目在循环中失败时跳过任务

python - Ansible 更新到 2.8 后找不到 Python 库

tomcat - 如何修复 Debian Wheezy 上缺少的 solr tomcat6 配置?