Aru*_*gal 3 stdout ansible ansible-2.x
ansible/ansible-playbook 版本:2.1.2.0 / 2.2.0.0
我正在尝试使用 yum/apt 安装软件包,但由于安装软件包的存储库位于 packagecloud.io 中,有时我会收到一条错误消息(当我在运行-vvvansible-playbook 时通过时)。
[Errno 14] curl#56 - \"TCP connection reset by peer\"\nTrying other mirror. ...some ansible verbose text here.. [Errno 256] No more mirrors to try.
Run Code Online (Sandbox Code Playgroud)
这种情况并不总是发生。如果我再次重新运行相同的剧本,它工作正常,因此失败(连接重置)是随机发生的。
为了解决这个问题,我想使用 Ansible 的until循环,我们必须将其与register变量一起使用。
因此,我通过引用 Ansible 文档创建了这个 playbook 操作,了解如何在此处until使用循环,但是使用该语法我收到一个“字典”错误,指出结果变量(注册) dict 没有任何名为stdout的键。然后我尝试使用 result.rc (关键字段),它在 CentOS 机器上工作,但在 Ubuntu 14.x 可信赖的 vagrant 机器上失败,并出现以下 result.rc dict not present 错误:
- name: Install telegraf agent/collector (RedHat)
yum:
name: "{{ agent_collector }}"
state: "installed"
when: ( ansible_os_family == 'RedHat' and company_install_collector == true )
register: result
until: result.stdout.find("Installed:") != -1
#The following works in CentOS/RedHat
#until: result.rc == 0
- debug: msg="result (redhat) = {{ result }}"
Run Code Online (Sandbox Code Playgroud)
或者(更新我的问题,这是显而易见的)
- name: Install Company Proxy (Ubuntu)
apt:
name: "{{ company_proxy_pkg }}"
state: "installed"
when: ( ansible_distribution == 'Ubuntu' and company_install_proxy == true )
register: result
until: result.rc == 0
- debug: msg="result (ubuntu) = {{ result }}"
Run Code Online (Sandbox Code Playgroud)
收到以下错误消息(result.stdout - dict object'在RedHat/CentOS和Ubuntu中没有属性'stdout',但仅在Ubuntu服务器中获取dict object没有属性'rc'):
fatal: [localhost]: FAILED! => {"failed": true, "msg": "The conditional check '(result.stdout.find(\"Installed:\") != -1)' failed. The error was: error while evaluating conditional ((result.stdout.find(\"Installed:\") != -1)): 'dict object' has no attribute 'stdout'"}
Run Code Online (Sandbox Code Playgroud)
和
fatal: [localhost]: FAILED! => {
"failed": true,
"msg": "The conditional check 'result.rc == 0' failed. The error was: error while evaluating conditional (result.rc == 0): 'dict object' has no attribute 'rc'"
}
Run Code Online (Sandbox Code Playgroud)
当文档说这些变量存在或者我可以在一个操作系统上以详细输出看到它们但它没有显示在另一个操作系统上时,为什么寄存器变量(在我的情况下是结果)没有或字典/变量?stdoutrc-vvv
| 归档时间: |
|
| 查看次数: |
16185 次 |
| 最近记录: |