[root@k8s-master ~]# ansible-playbook /etc/ansible/copy.yml
PLAY [webservers] **************************************************************************************************************************************************************************************
TASK [copy files] **************************************************************************************************************************************************************************************
failed: [192.168.10.149] (item={u'dest': u'/root/copytest4.txt', u'src': u'/root/copytest4.txt'}) => {"ansible_loop_var": "item", "item": {"dest": "/root/copytest4.txt", "src": "/root/copytest4.txt"}, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}
fatal: [192.168.10.149]: UNREACHABLE! => {"changed": false, "msg": "All items completed", "results": [{"ansible_loop_var": "item", "item": {"dest": "/root/copytest4.txt", "src": "/root/copytest4.txt"}, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}]}
failed: [192.168.10.150] (item={u'dest': u'/root/copytest4.txt', u'src': u'/root/copytest4.txt'}) => {"ansible_loop_var": "item", "item": {"dest": "/root/copytest4.txt", "src": "/root/copytest4.txt"}, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}
failed: [192.168.10.148] (item={u'dest': u'/root/copytest4.txt', u'src': u'/root/copytest4.txt'}) => {"ansible_loop_var": "item", "item": {"dest": "/root/copytest4.txt", "src": "/root/copytest4.txt"}, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}
fatal: [192.168.10.150]: UNREACHABLE! => {"changed": false, "msg": "All items completed", "results": [{"ansible_loop_var": "item", "item": {"dest": "/root/copytest4.txt", "src": "/root/copytest4.txt"}, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}]}
fatal: [192.168.10.148]: UNREACHABLE! => {"changed": false, "msg": "All items completed", "results": [{"ansible_loop_var": "item", "item": {"dest": "/root/copytest4.txt", "src": "/root/copytest4.txt"}, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}]}
看到这个报错脑袋大,直到翻阅官网的github 找到解决
[root@k8s-master ~]# ansible all -m ping --ask-pass
SSH password:
192.168.10.148 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
192.168.10.150 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
192.168.10.149 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
- [root@k8s-master ~]# cat /etc/ansible/zip.yml
- ---
- - hosts: webservers
- gather_facts: no
- become: yes
- become_method: sudo
- tasks:
- - name: "copy files"
- copy:
- src: "{{ item.src }}"
- dest: "{{ item.dest }}"
- owner: root
- group: root
- mode: 755
- with_items:
- - {src: "/root/copytest4.txt", dest: "/root/copytest4.txt" }
- - {src: "/root/dist.zip", dest: "/root/dist.zip" }
- - name: "unzip files"
- shell: unzip /root/dist.zip -d /tmp
- root@k8s-master ~]# cat /etc/ansible/hosts
- # This is the default ansible 'hosts' file.
- #
- # It should live in /etc/ansible/hosts
- #
- # - Comments begin with the '#' character
- # - Blank lines are ignored
- # - Groups of hosts are delimited by [header] elements
- # - You can enter hostnames or ip addresses
- # - A hostname/ip can be a member of multiple groups
-
- # Ex 1: Ungrouped hosts, specify before any group headers.
-
- ## green.example.com
- ## blue.example.com
- ## 192.168.100.1
- ## 192.168.100.10
-
- # Ex 2: A collection of hosts belonging to the 'webservers' group
-
- [webservers]
- ## alpha.example.org
- ## beta.example.org
- 192.168.10.149
- 192.168.10.148
- 192.168.10.150