• 优化-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
    用一个例子来演示会更加清晰
  • 相关阅读:
    Xamarin.Forms
    Docker Azure Kubernetes
    出现( linker command failed with exit code 1)错误总结(http://blog.csdn.net/hengshujiyi/article/details/21182813)
    UITextView学习笔记
    UIScrollView学习笔记
    如何学习ios(摘自知乎https://www.zhihu.com/question/20016551)
    iOS手势操作,拖动,轻击,捏合,旋转,长按,自定义(http://www.cnblogs.com/huangjianwu/p/4675648.html)
    触屏事件
    给UITextView添加链接
    IOS绘图详解(http://blog.163.com/wkyuyang_001/blog/static/10802122820133190545227/)
  • 原文地址:https://www.cnblogs.com/hixiaowei/p/13887583.html
Copyright © 2020-2023  润新知