ansible - Ansible 不返回异步任务的作业 ID
问题描述
根据文档,当我运行 async ad hoc 命令时,我应该得到一个作业 ID,以便稍后检查状态。这没有发生:
$ ansible all -a "sleep 60" -P 0 -B 86400
node1 | SUCCESS | rc=-1 >>
node2 | SUCCESS | rc=-1 >>
node0 | SUCCESS | rc=-1 >>
node3 | SUCCESS | rc=-1 >>
$
该sleep
命令在所有节点上运行,因此该任务确实运行正确:
$ ssh node2 ps aux | grep sleep
$ ansible node2 --user ${USER} --background 3600 --poll 0 --args "/bin/sleep 10s"
node2 | SUCCESS | rc=-1 >>
$ ssh node2 ps aux | grep sleep
user 7232 0.0 0.0 7468 744 ? S 13:54 0:00 /bin/sleep 10s
$
但是async_status
由于我不知道作业 ID,所以我无法检查作业的状态。有没有办法列出当前正在运行的异步作业?或者其他获取工作ID的方法?
Ubuntu 18.04.1、ansible 2.5.1、python 2.7.17。
解决方案
根据您的输出,返回代码rc=-1
和命令sleep
仅没有完整路径。
在具有 Ansible 2.9.25 和 Python 2.7.5 的 RHEL7.9.9 系统上,用户的异步临时任务的输出看起来像
ansible test --user ${USER} --ask-pass --background 3600 --poll 0 --args "/usr/bin/sleep 1m"
SSH password:
test1.example.com | CHANGED => {
"ansible_job_id": "211363790122.167971",
"changed": true,
"finished": 0,
"results_file": "/home/test/.ansible_async/211363790122.167971",
"started": 1
}
test2.example.com | CHANGED => {
"ansible_job_id": "289811848480.63295",
"changed": true,
"finished": 0,
"results_file": "/home/test/.ansible_async/289811848480.63295",
"started": 1
}
对于超级用户来说
ansible test --user ${USER} --ask-pass --become --background 3600 --poll 0 --args "/usr/bin/sleep 1m"
SSH password:
test1.example.com | CHANGED => {
"ansible_job_id": "494650580974.167671",
"changed": true,
"finished": 0,
"results_file": "/root/.ansible_async/494650580974.167671",
"started": 1
}
test2.example.com | CHANGED => {
"ansible_job_id": "273855897479.62987",
"changed": true,
"finished": 0,
"results_file": "/root/.ansible_async/273855897479.62987",
"started": 1
}
您可以使用几个不同的临时命令执行一些测试,例如
ansible test --user ${USER} --ask-pass --args "python --version"
SSH password:
test1.example.com | CHANGED | rc=0 >>
Python 2.7.5
test2.example.com | CHANGED | rc=0 >>
Python 2.7.5
有和没有完整路径等等。也因为rc=-1
ansible test --user ${USER} --ask-pass --module-name shell --args "echo test; echo rc=$?"
test1.example.com | CHANGED | rc=0 >>
test
rc=0
ansible test --user ${USER} --ask-pass --module-name shell --args "echo 'test '; exit -1;"
test1.example.com | FAILED | rc=255 >>
test non-zero return code
推荐阅读
- java - java这种类型的注释类型未知
- java - Swift 中的 putInt Java 等效方法
- angular - 跳过 Angular 8 和 Apache 中特定路径的 URL 路由
- java - 你好,我可以问一些关于java(Abstract,getter,setter)的问题吗?
- laravel - 如何有条件地在 Kernel.php 中加载 Laravel 中间件?
- java - 应用程序请求为空后使用 Autowired 获取实例
- python-3.x - Get KeyValue from Cloudformation Output with Python Boto3
- c - C reference static memory from initially allocated array
- python-3.x - Python - 为什么字符串变量不能在函数中“解析”正确?
- java - Java:如何使用 Luhn 检查和使用方法检查信用卡的有效性