设为首页 收藏本站
查看: 988|回复: 0

[经验分享] ansible学习笔记8-简单测试

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-5-19 09:00:54 | 显示全部楼层 |阅读模式
之前了解了hosts、vars、tasks、模块、handlers

下面结合使用下

cat test.yml
---
- hosts: 192.168.80.20
  tasks:
    - name: install httpd
      yum: name=httpd state=installed
      notify:
          - restart httpd
  handlers:
    - name: restart httpd
      service: name=httpd state=restarted

这个例子很简单,对20这台机器做操作,yum安装httpd服务,安装完后执行重启httpd的操作

通过-vvv我们可以看到更加详细的信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
ansible-playbook test.yml -vvv
Using /etc/ansible/ansible.cfg as config file

PLAYBOOK: test.yml *************************************************************
1 plays in test.yml

PLAY [192.168.80.20] ***********************************************************

TASK [setup] *******************************************************************
<192.168.80.20> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.80.20> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.80.20 '/bin/sh -c '"'"'( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1463550446.91-262274803314712 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1463550446.91-262274803314712 `" )'"'"''
<192.168.80.20> PUT /tmp/tmpJiMRZA TO /root/.ansible/tmp/ansible-tmp-1463550446.91-262274803314712/setup
<192.168.80.20> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.80.20]'
<192.168.80.20> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.80.20> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.80.20 '/bin/sh -c '"'"'LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 LC_MESSAGES=zh_CN.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1463550446.91-262274803314712/setup; rm -rf "/root/.ansible/tmp/ansible-tmp-1463550446.91-262274803314712/" > /dev/null 2>&1'"'"''
ok: [192.168.80.20]

TASK [install httpd] ***********************************************************
task path: /etc/ansible/test.yml:4
<192.168.80.20> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.80.20> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.80.20 '/bin/sh -c '"'"'( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1463550447.45-214190886104092 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1463550447.45-214190886104092 `" )'"'"''
<192.168.80.20> PUT /tmp/tmpJiMRZA TO /root/.ansible/tmp/ansible-tmp-1463550447.45-214190886104092/yum
<192.168.80.20> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.80.20]'
<192.168.80.20> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.80.20> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.80.20 '/bin/sh -c '"'"'LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 LC_MESSAGES=zh_CN.UTF-8 /usr/bin/python -tt /root/.ansible/tmp/ansible-tmp-1463550447.45-214190886104092/yum; rm -rf "/root/.ansible/tmp/ansible-tmp-1463550447.45-214190886104092/" > /dev/null 2>&1'"'"''
NOTIFIED HANDLER restart httpd
changed: [192.168.80.20] => {"changed": true, "invocation": {"module_args": {"conf_file": null, "disable_gpg_check": false, "disablerepo": null, "enablerepo": null, "exclude": null, "install_repoquery": true, "list": null, "name": ["httpd"], "state": "installed", "update_cache": false}, "module_name": "yum"}, "msg": "Warning: RPMDB altered outside of yum.\n", "rc": 0, "results": ["Loaded plugins: fastestmirror, refresh-packagekit, security\nLoading mirror speeds from cached hostfile\n * base: mirrors.yun-idc.com\n * extras: mirrors.yun-idc.com\n * updates: mirrors.sina.cn\nSetting up Install Process\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.2.15-47.el6.centos.4 will be installed\n--> Processing Dependency: httpd-tools = 2.2.15-47.el6.centos.4 for package: httpd-2.2.15-47.el6.centos.4.x86_64\n--> Running transaction check\n---> Package httpd-tools.x86_64 0:2.2.15-47.el6.centos.4 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package          Arch        Version                        Repository    Size\n================================================================================\nInstalling:\n httpd            x86_64      2.2.15-47.el6.centos.4         updates      831 k\nInstalling for dependencies:\n httpd-tools      x86_64      2.2.15-47.el6.centos.4         updates       77 k\n\nTransaction Summary\n================================================================================\nInstall       2 Package(s)\n\nTotal download size: 908 k\nInstalled size: 3.1 M\nDownloading Packages:\n--------------------------------------------------------------------------------\nTotal                                            78 kB/s | 908 kB     00:11     \nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r  Installing : httpd-tools-2.2.15-47.el6.centos.4.x86_64                    1/2 \n\r  Installing : httpd-2.2.15-47.el6.centos.4.x86_64                          2/2 \n\r  Verifying  : httpd-2.2.15-47.el6.centos.4.x86_64                          1/2 \n\r  Verifying  : httpd-tools-2.2.15-47.el6.centos.4.x86_64                    2/2 \n\nInstalled:\n  httpd.x86_64 0:2.2.15-47.el6.centos.4                                         \n\nDependency Installed:\n  httpd-tools.x86_64 0:2.2.15-47.el6.centos.4                                   \n\nComplete!\n"]}

RUNNING HANDLER [restart httpd] ************************************************
<192.168.80.20> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.80.20> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.80.20 '/bin/sh -c '"'"'( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1463550464.02-33682846723600 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1463550464.02-33682846723600 `" )'"'"''
<192.168.80.20> PUT /tmp/tmpJiMRZA TO /root/.ansible/tmp/ansible-tmp-1463550464.02-33682846723600/service
<192.168.80.20> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.80.20]'
<192.168.80.20> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.80.20> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.80.20 '/bin/sh -c '"'"'LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 LC_MESSAGES=zh_CN.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1463550464.02-33682846723600/service; rm -rf "/root/.ansible/tmp/ansible-tmp-1463550464.02-33682846723600/" > /dev/null 2>&1'"'"''
changed: [192.168.80.20] => {"changed": true, "invocation": {"module_args": {"arguments": "", "enabled": null, "name": "httpd", "pattern": null, "runlevel": "default", "sleep": null, "state": "restarted"}, "module_name": "service"}, "name": "httpd", "state": "started"}

PLAY RECAP *********************************************************************
192.168.80.20              : ok=3    changed=2    unreachable=0    failed=0






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-218937-1-1.html 上篇帖子: ansible学习笔记9-playbooks之include 下篇帖子: ansible学习笔记7-playbooks之执行一个playbook
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表