大网数据广告活动
服务器运维问答

Returning python script value and using that in the ansible task

· 52CE 我爱测

I am new to Ansible and a bit stuck. I have a python script that returns true or false. I run this python script via ansible task. I am trying to debug the value returned by running the py script. Additionally I would want to run…

问题原文

原帖链接 · Coder · CC BY-SA 4.0

I am new to Ansible and a bit stuck.

I have a python script that returns true or false.

I run this python script via ansible task.

I am trying to debug the value returned by running the py script. Additionally I would want to run another task only if the value returned is true.

Ansible Task below:

---
- name: Check XML against XSD
  become: yes
  shell: /usr/bin/python3 check.py
  args:
    chdir: "/var/www/html/det/scripts/"
  register: result
  tags: schema_check

- debug: var =schema_check.stdout
    msg: "Testing..."
    verbosity: 2

And the python script check.py

result = true
print(result)

已采纳解答

原帖链接 · Cavaz · CC BY-SA 4.0

The issue here is you are registering the output as result, while in the debug task you are calling schema_check, which is the name of the tag.

Furthermore debug can only have either the var or the msg property, not both at the same time.

- debug:
    var: result.stdout

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-07-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。