配置Linux主機無密碼訪問
生成秘鑰
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
73:80:07:fa:9a:0d:e0:0e:d1:c2:44:d2:d2:61:67:21 root@ansible
The key's randomart image is:
+--[ RSA 2048]----+
|o=E.+.. |
|=oo+ . o |
|ooo . . o |
| + . . . . |
|. . . . S . |
| o = o |
| . o . |
| |
| |
+-----------------+
將管理機上生成的秘鑰發送到被管理機
ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.16.1.10
ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.16.1.10
測試是否不需要密碼直接執行任務
ansible test -a "date"
172.16.1.10 | SUCCESS | rc=0 >>
Fri Apr 6 21:47:21 CST 2018
172.16.1.11 | SUCCESS | rc=0 >>
Fri Apr 6 21:47:21 CST 2018
執行Ansible任務時的排錯
通過Ansible執行任務時代上-v參數,打開調試模式(加的v個數越多調試的輸出信息越多,最多4個v):
-v的情況下:
ansible test -a "date" -v
Using /etc/ansible/ansible.cfg as config file
172.16.1.11 | SUCCESS | rc=0 >>
Fri Apr 6 21:49:43 CST 2018
172.16.1.10 | SUCCESS | rc=0 >>
Fri Apr 6 21:49:43 CST 2018
-vv的情況下:
ansible test -a "date" -vv
ansible 2.4.2.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Nov 20 2015, 02:00:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
Using /etc/ansible/ansible.cfg as config file
META: ran handlers
172.16.1.11 | SUCCESS | rc=0 >>
Fri Apr 6 21:49:47 CST 2018
172.16.1.10 | SUCCESS | rc=0 >>
Fri Apr 6 21:49:47 CST 2018
META: ran handlers
META: ran handlers