码迷,mamicode.com
首页 > 其他好文 > 详细

ansible使用sudo

时间:2019-02-07 12:18:02      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:std   ati   tar   port   login   执行命令   ica   rest   system   

方式一、

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、但是无法创建用户



方式二、


1、给客户端普通用户配置sudo权限


2、配置主机组

cat >/etc/ansible/hosts<<EOF
[k8s]
192.168.0.92 

[test3]
192.168.0.93  


3、执行

sudo ansible k8s -m shell -a chmod +x /home/*













 

 

ansible使用sudo

标签:std   ati   tar   port   login   执行命令   ica   rest   system   

原文地址:https://www.cnblogs.com/effortsing/p/10354582.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!