【发布时间】:2022-01-03 09:01:11
【问题描述】:
我的 ansible-playbook 正在运行一些带有异步标记的长时间运行的任务,并且还利用“creates:”条件,因此它只在服务器上运行一次。昨天写剧本的时候,我很确定,当“creates:”标签中设置的日志存在时,任务被跳过了。
不过,现在每次我运行它时,它都会显示变化。
我很困惑,因为我认为我没有更改任何内容,并且我想在条件为真时正确地将我的注册变量设置为未更改。
ansible-play 的输出(调试部分显示任务已更改:true):
TASK [singleserver : Install Assure1 SingleServer role] *********************************************************************************************************************************
changed: [crassure1]
TASK [singleserver : Debug] *************************************************************************************************************************************************************
ok: [crassure1] => {
"msg": {
"ansible_job_id": "637594935242.28556",
"changed": true,
"failed": false,
"finished": 0,
"results_file": "/root/.ansible_async/637594935242.28556",
"started": 1
}
}
但是如果我检查目标机器上的实际结果文件,它正确地解决了条件并且没有实际执行 shell 脚本,所以任务应该没有改变(显示消息任务被跳过,因为日志存在):
[root@crassure1 assure1]# cat "/root/.ansible_async/637594935242.28556"
{"invocation": {"module_args": {"warn": true, "executable": null, "_uses_shell": true, "strip_empty_ends": true, "_raw_params": "/opt/install/install_command.sh", "removes": null, "argv": null, "creates": "/opt/assure1/logs/SetupWizard.log", "chdir": null, "stdin_add_newline": true, "stdin": null}}, "cmd": "/opt/install/install_command.sh", "changed": false, "rc": 0, "stdout": "skipped, since /opt/assure1/logs/SetupWizard.log exists"}[root@crassure1 assure1]# Connection reset by 172.24.36.123 port 22
我的剧本部分如下所示:
- name: Install Assure1 SingleServer role
shell:
#cmd: "/opt/assure1/bin/SetupWizard -a --Depot /opt/install/:a1-local --First --WebFQDN crassure1.tspdata.local --Roles All"
cmd: "/opt/install/install_command.sh"
async: 7200
poll: 0
register: Assure1InstallWait
args:
creates: /opt/assure1/logs/SetupWizard.log
- name: Debug
debug:
msg: "{{ Assure1InstallWait }}"
- name: Check on Installation status every 15 minutes
async_status:
jid: "{{ Assure1InstallWait.ansible_job_id }}"
register: job_result
until: job_result.finished
retries: 30
delay: 900
when: Assure1InstallWait is changed
是我遗漏了什么,还是某种错误?
我受到配置的受信任仓库中可用的 Ansible 版本的限制,因此我使用的是 ansible 2.9.25
【问题讨论】:
标签: asynchronous ansible