当前位置: 首页 > news >正文

完成公司门户网站建设吉林省建设工程安管人员管理系统

完成公司门户网站建设,吉林省建设工程安管人员管理系统,重庆最有效的网站推广,html个人主页模板Ansible的Ad-hoc命令执行流程 用了这么久的Ansible#xff0c;今天想着研究下Ad-hoc命令的执行流程#xff0c;从最简单的ping开始吧。 测试命令如下#xff1a; ansible 172.18.2.31 -m ping先看看回显的结果 [rootbigdata-m-002 etc]# ansible 172.18.2.31 -m ping 17…Ansible的Ad-hoc命令执行流程 用了这么久的Ansible今天想着研究下Ad-hoc命令的执行流程从最简单的ping开始吧。 测试命令如下 ansible 172.18.2.31 -m ping先看看回显的结果 [rootbigdata-m-002 etc]# ansible 172.18.2.31 -m ping 172.18.2.31 | SUCCESS {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong }内容很少加上-vvv查看详细的信息 [rootbigdata-m-002 etc]# ansible 172.18.2.31 -m ping -vvv Using /etc/ansible/ansible.cfg as config file host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method META: ran handlers 172.18.2.31 Attempting python interpreter discovery 172.18.2.31 ESTABLISH SSH CONNECTION FOR USER: None 172.18.2.31 SSH: EXEC ssh -C -o ControlMasterauto -o ControlPersist60s -o KbdInteractiveAuthenticationno -o PreferredAuthenticationsgssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthenticationno -o ConnectTimeout10 -o ControlPath/root/.ansible/cp/414e6c60fc 172.18.2.31 /bin/sh -c echo PLATFORM; uname; echo FOUND; command -v /usr/bin/python; command -v python3.7; command -v python3.6; command -v python3.5; command -v python2.7; command -v python2.6; command -v /usr/libexec/platform-python; command -v /usr/bin/python3; command -v python; echo ENDFOUND sleep 0 172.18.2.31 (0, PLATFORM\nLinux\nFOUND\n/usr/bin/python\n/usr/bin/python2.7\n/usr/libexec/platform-python\n/usr/bin/python\nENDFOUND\n, ) 172.18.2.31 ESTABLISH SSH CONNECTION FOR USER: None 172.18.2.31 SSH: EXEC ssh -C -o ControlMasterauto -o ControlPersist60s -o KbdInteractiveAuthenticationno -o PreferredAuthenticationsgssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthenticationno -o ConnectTimeout10 -o ControlPath/root/.ansible/cp/414e6c60fc 172.18.2.31 /bin/sh -c /usr/bin/python sleep 0 172.18.2.31 (0, {osrelease_content: NAME\\CentOS Linux\\\\nVERSION\\7 (Core)\\\\nID\\centos\\\\nID_LIKE\\rhel fedora\\\\nVERSION_ID\\7\\\\nPRETTY_NAME\\CentOS Linux 7 (Core)\\\\nANSI_COLOR\\0;31\\\\nCPE_NAME\\cpe:/o:centos:centos:7\\\\nHOME_URL\\https://www.centos.org/\\\\nBUG_REPORT_URL\\https://bugs.centos.org/\\\\n\\nCENTOS_MANTISBT_PROJECT\\CentOS-7\\\\nCENTOS_MANTISBT_PROJECT_VERSION\\7\\\\nREDHAT_SUPPORT_PRODUCT\\centos\\\\nREDHAT_SUPPORT_PRODUCT_VERSION\\7\\\\n\\n, platform_dist_result: [centos, 7.8.2003, Core]}\n, ) Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/ping.py Pipelining is enabled. 172.18.2.31 ESTABLISH SSH CONNECTION FOR USER: None 172.18.2.31 SSH: EXEC ssh -C -o ControlMasterauto -o ControlPersist60s -o KbdInteractiveAuthenticationno -o PreferredAuthenticationsgssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthenticationno -o ConnectTimeout10 -o ControlPath/root/.ansible/cp/414e6c60fc 172.18.2.31 /bin/sh -c /usr/bin/python sleep 0 172.18.2.31 (0, \n{invocation: {module_args: {data: pong}}, ping: pong}\n, ) 172.18.2.31 | SUCCESS {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, invocation: {module_args: {data: pong}}, ping: pong } META: ran handlers META: ran handlers上述的命令删除了一部分不必要的内容主要是了解一下整个执行的过程首先ansible会读取ansible.cfg作为配置文件这个是默认的配置文件位置随后ansible读取主机配置文件获得远程服务器的ip信息以及可能存在的变量信息。 接下来ansible会尝试搜索远程的python解释器也就是下面的命令 SSH: EXEC ssh -C -o ControlMasterauto -o ControlPersist60s -o KbdInteractiveAuthenticationno -o PreferredAuthenticationsgssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthenticationno -o ConnectTimeout10 -o ControlPath/root/.ansible/cp/414e6c60fc 172.18.2.31 /bin/sh -c echo PLATFORM; uname; echo FOUND; command -v /usr/bin/python; command -v python3.7; command -v python3.6; command -v python3.5; command -v python2.7; command -v python2.6; command -v /usr/libexec/platform-python; command -v /usr/bin/python3; command -v python; echo ENDFOUND sleep 0command -v可以搜寻指定命令的绝对路径此处搜索的命令清单定义在base.yml文件中 INTERPRETER_PYTHON_FALLBACK:name: Ordered list of Python interpreters to check for in discoverydefault:- /usr/bin/python- python3.7- python3.6- python3.5- python2.7- python2.6- /usr/libexec/platform-python- /usr/bin/python3- python接下来Ansible会默认以拿到的第一个python路径作为运行远程脚本的解释器并以此开启交互页也就是这个命令的作用 ssh -C -o ControlMasterauto -o ControlPersist60s -o KbdInteractiveAuthenticationno -o PreferredAuthenticationsgssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthenticationno -o ConnectTimeout10 -o ControlPath/root/.ansible/cp/414e6c60fc 172.18.2.31 /bin/sh -c /usr/bin/python sleep 0这里并没有打印出具体执行的逻辑只有一个/usr/bin/python实际上这是一个交互窗口接下来会在这个交互窗口中执行python脚本的逻辑首先会执行executor/discovery/python_target.py的逻辑获取一些操作系统的基本信息 [rootbigdata-m-002 etc]# python /usr/lib/python2.7/site-packages/ansible/executor/discovery/python_target.py {osrelease_content: NAME\CentOS Linux\\nVERSION\7 (Core)\\nID\centos\\nID_LIKE\rhel fedora\\nVERSION_ID\7\\nPRETTY_NAME\CentOS Linux 7 (Core)\\nANSI_COLOR\0;31\\nCPE_NAME\cpe:/o:centos:centos:7\\nHOME_URL\https://www.centos.org/\\nBUG_REPORT_URL\https://bugs.centos.org/\\n\nCENTOS_MANTISBT_PROJECT\CentOS-7\\nCENTOS_MANTISBT_PROJECT_VERSION\7\\nREDHAT_SUPPORT_PRODUCT\centos\\nREDHAT_SUPPORT_PRODUCT_VERSION\7\\n\n, platform_dist_result: [centos, 7.8.2003, Core]}随后就是准备执行模块的业务逻辑了这里以ping模块为例在执行具体的模块业务逻辑前模块依赖的所有脚本文件都会被打包在一个python文件中类似这样 [rootbigdata-m-002 ansible-tmp-1699492620.36-27101-107096752350654]# ll total 112 -rwx------. 1 root root 114480 Nov 9 14:10 AnsiballZ_ping.py这个脚本的内容会通过定义的标准输入写进交互界面进行执行如果手动执行就可以看到其回显的结果正是我们执行ansible的时候回显的结果只不过ansible用自己的回调进行了处理 [rootbigdata-m-002 ansible-tmp-1699492620.36-27101-107096752350654]# python AnsiballZ_ping.py {invocation: {module_args: {data: pong}}, ping: pong} [rootbigdata-m-002 ansible-tmp-1699492620.36-27101-107096752350654]# 而这个脚本中有个变量ZIP_DATA就是把相关依赖文件被转换成了base64加密的一串字符稍后ansible会将这些字符以文件流的方式再写入zip文件然后进行解压从而得到一系列依赖python [rootbigdata-m-002 ansible_ping_payload_zNTlb2]# tree . ├── ansible │ ├── __init__.py │ ├── modules │ │ ├── __init__.py │ │ └── system │ │ ├── __init__.py │ │ └── ping.py │ └── module_utils │ ├── basic.py │ ├── common │ │ ├── _collections_compat.py │ │ ├── collections.py │ │ ├── file.py │ │ ├── __init__.py │ │ ├── _json_compat.py │ │ ├── parameters.py │ │ ├── process.py │ │ ├── sys_info.py │ │ ├── text │ │ │ ├── converters.py │ │ │ ├── formatters.py │ │ │ └── __init__.py │ │ ├── _utils.py │ │ └── validation.py │ ├── compat │ │ ├── __init__.py │ │ ├── _selectors2.py │ │ └── selectors.py │ ├── distro │ │ ├── _distro.py │ │ └── __init__.py │ ├── __init__.py │ ├── parsing │ │ ├── convert_bool.py │ │ └── __init__.py │ ├── pycompat24.py │ ├── six │ │ └── __init__.py │ └── _text.py ├── ansible_ping_payload.zip └── sitecustomize.py如果去看了ping的实现逻辑我们就知道ansible的ping其实不是发送icmp包实现的而是尝试在远程服务器上打印data不过如果你的data给的值是crashansible会给你抛出一个boom的错误 from ansible.module_utils.basic import AnsibleModuledef main():module AnsibleModule(argument_specdict(datadict(typestr, defaultpong),),supports_check_modeTrue)if module.params[data] crash:raise Exception(boom)result dict(pingmodule.params[data],)module.exit_json(**result)if __name__ __main__:main() 可能这就是开发人员的恶趣味吧~
http://www.dnsts.com.cn/news/255135.html

相关文章:

  • 设计网站大全下载程序员招聘求职的网站
  • 旅行社网站方案memcached集群WordPress
  • 做告状网站安徽网站建设价格
  • 做网站要花钱吗深圳企业电话黄页
  • 网站建设 厦门网页版扫一扫二维码
  • 网站建设内容的重点安徽常青建设集团网站
  • 2017建设厅网站做网站就用建站之星
  • 做网站销售好不好做商城网站的风险
  • 如何免费创建网站平台长沙网站建设与维护
  • 想做cpa 没有网站怎么做商务网站开发综合实训
  • 一般网站宽度排名优化方法
  • 中国建设局网站招聘一个几个人做网站的几个故事电影
  • wed网站开发是什么西安百度搜索排名
  • 绍兴市建设银行网站网站开发编程入门学习
  • flash制作网站界面网站内容由什么组成部分
  • 深圳网站推广公司公众号怎么开通
  • 专业建站公司wordpress论坛系统
  • layui做移动网站泰安seo排名
  • 网站如何做二级栏目公司网站经常打不开
  • 网站怎么做弹窗吧台 东莞网站建设
  • 外国可以做站外推广的网站龙华网站建设网站定制
  • 东莞装饰网站建设做网站用windows还是linux
  • 廊坊做网站教程wordpress标签多重筛选
  • wordpress 查看站点网站数据库怎么恢复
  • 域名注册流程及费用站长工具seo查询5g5g
  • 云南网站制作案例竞价推广案例
  • 聚美优品网站建设的特点优质的聊城网站建设
  • 湖南网站建设案例建网站网
  • 北京企业建网站网站建设模块是什么意思
  • 做网站标题头像新乡seo外包