本文介绍了通过Ansible剧本检查Java版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的剧本:

---
- hosts: UAT
  gather_facts: false
  remote_user: xxxx
  become_method: sudo
  become: yes
  become_user: sudo_user
  tasks:
   - name: Fetch Java version
     command: java -version
     register: java_result
     ignore_errors: True
   - debug: "msg={{ java_result.stdout }}"
...

我收到以下错误:

fatal: [ma-dsast-lapp10]: FAILED! => {
    "changed": false,
    "cmd": "java -version '2>&1' '|' grep version",
    "failed": true,
    "invocation": {
        "module_args": {
            "_raw_params": "java -version 2>&1 | grep version",
            "_uses_shell": false,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "warn": true
        }
    },
    "msg": "[Errno 2] No such file or directory",
    "rc": 2
}

我得到了:没有这样的文件或目录错误

Im getting : No such file or directory error

这可能是什么问题?请帮助我.

What could be the issue with this?Please help me on this.

推荐答案

我在计算机上运行了您的脚本,但该脚本也不起作用.我做了一点修改

I ran your script on my machine and it did not work either. I modified it a little bit

---

- hosts: localhost
  gather_facts: False

  tasks:
   - name: Fetch Java version
     shell: java -version 2>&1 | grep version | awk '{print $3}' | sed 's/"//g'                                                                                                                                   
     changed_when: False
     register: java_result

   - debug:
       msg: "{{ java_result.stdout }}"

我知道了

TASK [debug] *******************************************************************************************
ok: [localhost] => {
    "msg": "1.8.0_181"
}

这篇关于通过Ansible剧本检查Java版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 02:03