zoukankan      html  css  js  c++  java
  • 优化-debug模块去确认返回结果的数据结构

    1.通过debug模块去确认返回结果的数据结构

    获取Task任务结果
    - name: check nginx syntax
      shell: /usr/sbin/nginx -t
      register: nginxsyntax
    
    通过debug模块去确认返回结果的数据结构
    - name: print nginx syntax result
      debug: var=nginxsyntax
    
    "nginxsyntax": {
            "changed": true,
            "cmd": "/usr/sbin/nginx -t",
            "delta": "0:00:00.012045",
            "end": "2017-08-12 20:19:04.650718",
            "rc": 0,
            "start": "2017-08-12 20:19:04.638673",
            "stderr": "nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful",
            "stderr_lines": [
                "nginx: the configuration file /etc/nginx/nginx.conf syntax is ok",
                "nginx: configuration file /etc/nginx/nginx.conf test is successful"
            ],
            "stdout": "",
            "stdout_lines": []
        }

    2.我的debug

    ---
    - name: a template example
      hosts: frame
      remote_user: root
      tasks:
        - name: max login try count
          shell: egrep -i 'MaxAuthTries'  /etc/ssh/sshd_config |awk '{print $2}'
          register: try_count
        - name: echo last shell result var
          debug: var=try_count
    
        - name: echo last shell result
          debug:
            msg: "{{ try_count['stdout_lines'] }}"

    TASK [max login try count] *************************************************************************************************************************
    changed: [10.0.0.4]

    
    

    TASK [echo last shell result var] ******************************************************************************************************************
    ok: [10.0.0.4] => {
    "try_count": {
    "changed": true,
    "cmd": "egrep -i 'MaxAuthTries' /etc/ssh/sshd_config |awk '{print $2}'",
    "delta": "0:00:00.050398",
    "end": "2020-10-27 21:05:05.333621",
    "failed": false,
    "rc": 0,
    "start": "2020-10-27 21:05:05.283223",
    "stderr": "",
    "stderr_lines": [],
    "stdout": "6",
    "stdout_lines": [
    "6"
    ]
    }
    }

    
    

    TASK [echo last shell result] **********************************************************************************************************************
    ok: [10.0.0.4] => {
    "msg": [
    "6"
    ]
    }

     

     3.Ansible中setup模块的执行过程,它是将setup模块的python脚本拷贝到ansible管控主机,

       然后在管控主机上执行python脚本获取主机基本信息,在返回给ansible。
       查看执行setup的主机,看到执行的python进程处于D状态。  

    参考:https://blog.csdn.net/weixin_34352449/article/details/92723102

    --------------------------------------------------------------------------------------------

    # 将要执行的任务放到临时文件中,并使用sftp将任务文件传输到被控节点上 https://www.cnblogs.com/hackerlin/p/12553155.html
    https://www.cnblogs.com/hackerlin/p/12553155.html
    用一个例子来演示会更加清晰
  • 相关阅读:
    48. Rotate Image
    83. Remove Duplicates from Sorted List
    46. Permutations
    HTML5笔记
    18. 4Sum
    24. Swap Nodes in Pairs
    42. Trapping Rain Water
    Python modf() 函数
    Python min() 函数
    Python max() 函数
  • 原文地址:https://www.cnblogs.com/hixiaowei/p/13887583.html
Copyright © 2011-2022 走看看