ansible学习笔记8-简单测试
之前了解了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 ***********************************************************
TASK *******************************************************************
<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> 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:
TASK ***********************************************************
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> 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: => {"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\rInstalling : httpd-tools-2.2.15-47.el6.centos.4.x86_64 1/2 \n\rInstalling : httpd-2.2.15-47.el6.centos.4.x86_64 2/2 \n\rVerifying: httpd-2.2.15-47.el6.centos.4.x86_64 1/2 \n\rVerifying: httpd-tools-2.2.15-47.el6.centos.4.x86_64 2/2 \n\nInstalled:\nhttpd.x86_64 0:2.2.15-47.el6.centos.4 \n\nDependency Installed:\nhttpd-tools.x86_64 0:2.2.15-47.el6.centos.4 \n\nComplete!\n"]}
RUNNING HANDLER ************************************************
<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> 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: => {"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]