首页 文章

Ansible:APT模块:如何获得stdout?

提问于
浏览
0

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

使用这个非常简单的测试手册:

- 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] }}

我总是有这个错误消息:

致命:[localhost]:失败! => {“msg”:“任务包含一个带有未定义变量的选项 . 错误是:'dict object'没有属性'stdout'

我尝试了很多方式(安装包,删除,...),并始终有相同的错误消息 .

使用 debug: msg=apt 我可以拥有的唯一输出消息是 {"cache_update_time": 1531941358, "cache_updated": true, "changed": true} ,即使我安装或删除了一个对我来说很简单的输出消息,这意味着什么都不清楚,因为 "cache_updated": true, "changed": true 并不意味着已经安装或删除了包 .

在Ansible APT模块文档Ansible APT Module Documentation返回值部分中,有一个stdout返回 success, when needed .

有没有人知道如何从Ansible APT模块中获得真实而明确的退出,或者如何强制Ansible返回stdout(ansible config,...)以及真正意味着 "success, * when needed *" 因为我在任何情况下都没有设法获得stdout输出 .

亲切的问候

2 回答

  • 0

    似乎对于某些操作没有真正的命令输出,正如我们所希望的那样 .

    所以 when needed 与执行的操作有关 .

    非常感谢techraf .

  • 0

    如果需要详细的apt stdout,则可以使用命令模块运行apt-get更新 .

    运行这个:

    -  hosts: target
          tasks:
          - name: 'apt test'
            command: apt-get update
            register: hello
    
          - debug: msg="{{ hello.stdout }}"
    

    Ansible将警告您使用apt模块,因为它具有某些类似功能的安全性 .

相关问题