LINUX如何 部署ansible

        主:192.168.170.49
        被:192.168.170.18


一、启动系统前,加一块光驱,把安装镜像文件放到光驱中

二、配置Yum文件
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rm -f *
[root@localhost yum.repos.d]# vi cdrom.repo
[BaseOS]
name=BaseOS
baseurl=file:///media/BaseOS
enabled=1
gpgcheck=0

[AppStream]
name=AppStream
baseurl=file:///media/AppStream
enabled=1
gpgcheck=0

[ansible]
name=ansible
baseurl=file:///mnt/ansible
enabled=1
gpgcheck=0

三、挂载光驱,安装ansible
mount /dev/sr1 /media
mount /dev/sr0 /mnt

yum -y install ansible


四、修改配置文件
cd  /etc/ansible/
vim hosts
192.168.1.20

vim ansible.cfg
[defaults]
inventory = /etc/ansible/hosts      
ask_pass = False                          
host_key_checking = False             
remote_user = marry                      
[privilege_escalation]                      
become=True
become_method=sudo
become_user=root
become_ask_pass=False


        主:192.168.170.49
        被:192.168.170.18

五、配置marry免密
1、在远程上新建用户marry
ansible all -m shell -a "useradd marry" -u root -k

2、修改marry的密码
ansible all -m shell -a "echo 123456 |passwd --stdin marry" -u root -k

3、生成公钥对
ssh-keygen

4、把marry的公钥传给被控192.168.1.20
ssh-copy-id marry@192.168.1.20

5、把marry用户提权到root
ansible all -m shell -a ‘echo marry ”ALL=(ALL) NOPASSWD:ALL”>>/etc/sudoers.d/marry’ -u root -k
    
6、测试一下
ansible node2 -m shell -a "ls /root" 

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值