Ansible:如何获得更多细节的输出

时间:2018-11-18 14:24:37

标签: ansible

我想知道是否可以从一本剧本中获得输出,例如运行一个可运行的命令行的详细信息。例如,我正在检查运行dzinfo命令的用户特权。

ansible server_name -m shell -a "/usr/bin/dzinfo some_user" -u user_name -b -k -K

输出为:

 Role Name        Avail Restricted Env 
---------------  ----- -------------- 
some-details                          

Effective rights:
    Password login
    Non password login
    Allow normal shell
    Visible

   Audit level:
    AuditIfPossible

Always permit login:
    false


 PAM Application  Avail Source Roles         
 ---------------  ----- -------------------- 
crond            Yes   some-role              
login            Yes   some-role             
sshd             Yes   some-role 

现在,一旦我运行了剧本,我收到的唯一信息就是:

PLAY RECAP 
some_server            : ok=2    changed=1    unreachable=0    failed=0              

有什么方法可以获取运行手册的详细输出吗?就像从上面可以看到特权详细信息的那一个一样?

1 个答案:

答案 0 :(得分:1)

您可以register任务的结果command,然后使用 随后的debug任务来显示它。例如,以下 剧本:

---
- hosts: localhost
  gather_facts: false
  tasks:
    - command: /usr/bin/dzinfo some_user
      register: dzinfo_output

    - debug:
        var: dzinfo_output.stdout_lines

可能会产生如下输出:

PLAY [localhost] ******************************************************************************

TASK [command] ********************************************************************************
changed: [localhost]

TASK [debug] **********************************************************************************
ok: [localhost] => {
    "dzinfo_output.stdout_lines": [
        " Role Name        Avail Restricted Env ",
        "---------------  ----- -------------- ",
        "some-details                          ",
        "",
        "Effective rights:",
        "    Password login",
        "    Non password login",
        "    Allow normal shell",
        "    Visible",
        "",
        "   Audit level:",
        "    AuditIfPossible",
        "",
        "Always permit login:",
        "    false",
        "",
        "",
        " PAM Application  Avail Source Roles         ",
        " ---------------  ----- -------------------- ",
        "crond            Yes   some-role              ",
        "login            Yes   some-role             ",
        "sshd             Yes   some-role "
    ]
}

PLAY RECAP ************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0