報錯1
執行ansible報錯python這一個
[DEPRECATION WARNING]: Distribution Ubuntu 16.04 on host k8s-node01 should use /usr/bin/python3, but is using /usr/bin/python for backward
compatibility with prior Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. This feature will be removed in
version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

報錯2
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},

解決
從上面可知基本都是意思遠程機器調用的python2,建議python3,看機器也是有的。
root@k8s-node01:/home/appdeploy# ls /usr/bin/python
python python2 python2.7 python3 python3.5 python3.5m python3m

那么在ansible的host內調用即可
k8s-node01 ansible_ssh_user=appdeploy ansible_ssh_port=51000 ansible_python_interpreter=/usr/bin/python3.5
k8s-node02 ansible_ssh_user=appdeploy ansible_ssh_port=51000 ansible_python_interpreter=/usr/bin/python3.5

修改后

ansible普通用戶執行命令
[
參考鏈接] https://blog.csdn.net/qq_34939308/article/details/110454215
生產中root都是禁止直接遠程登錄得。很多命令root權限才能執行,腳本使用expect提權又麻煩,還好ansible自帶有這功能。
修改下列配置文件
root@k8s-master01:~# cat /etc/ansible/ansible.cfg
[defaults]
timeout = 30
remote_user = root
[inventory]
[privilege_escalation]
become=True ###表示打開become開關,也就是輸入密碼那一欄
become_method=su ###表示用什么方式將普通賬戶切換到root或所需的其他賬戶,這里可以用su或sudo
become_user=root ##***設置為root賬戶,相當於我們以普通賬戶登入到遠程主機時,再使用su - root切換為root賬戶。
become_ask_pass=True ###表示詢問密碼
[paramiko_connection]
[ssh_connection]
[persistent_connection]
[accelerate]
[selinux]
[colors]
[diff]
修改后執行root權限得命令會彈出讓你輸入BECOME密碼(也就是你遠程主機root的密碼),然后執行成功。

附上其他兩個配置文件參考:
ansible主機配置文件

root@k8s-master01:~# cat /etc/ansible/hosts |grep -Ev '^$|#'
[k8s]
k8s-node01 ansible_ssh_user=appdeploy ansible_ssh_port=51000 ansible_python_interpreter=/usr/bin/python3.5
k8s-node02 ansible_ssh_user=appdeploy ansible_ssh_port=51000 ansible_python_interpreter=/usr/bin/python3.5
root@k8s-master01:~# fengliuxiaosanyuanchuang
系統主機hosts文件

root@k8s-master01:~# cat /etc/hosts |grep -Ev '^$|#'
127.0.0.1 localhost
127.0.1.1 ubuntu
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.202.128 k8s-master01
192.168.202.132 k8s-node01
192.168.202.130 k8s-node02
