微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ansible使用sudo

1、配置资源清单inventory文件

[root@test1 ~]#
cat >/etc/ansible/hosts <<EOF
[k8s]
192.168.0.92 ansible_ssh_port=22 ansible_ssh_user=k8s ansible_ssh_pass='123' ansible_become_pass='123456'
EOF


解释:

ansible_ssh_pass='123'         是客户端普通用户密码
ansible_become_pass='123456'   是客户端root用户密码



2、Ansile客户端禁止root直接远程登陆,并创建普通用户ywbz

[root@test2 ~]# grep -n "PermitRootLogin" /etc/ssh/sshd_config 
PermitRootLogin no
[root@test2 ~]# systemctl restart sshd
[root@test2 ~]# useradd k8s
[root@test2 ~]# echo '123' | passwd --stdin k8s
Changing password for user k8s.
passwd: all authentication tokens updated successfully.
[root@test1 ~]# 


3、服务端测试执行命令

[k8s@test1 root]$ ansible test3 -m shell -a 'chmod +x /home/*'


4、但是无法创建用户

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐