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" 

相关推荐

  1. LINUX如何 部署ansible

    2024-04-25 22:42:01       32 阅读
  2. ansible自动化部署(playbook)

    2024-04-25 22:42:01       41 阅读
  3. Linux系统安装ansible

    2024-04-25 22:42:01       36 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-25 22:42:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-25 22:42:01       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-25 22:42:01       82 阅读
  4. Python语言-面向对象

    2024-04-25 22:42:01       91 阅读

热门阅读

  1. python之schedule

    2024-04-25 22:42:01       37 阅读
  2. 什么是layer1,layer2,为什么区块链需要layer2?

    2024-04-25 22:42:01       33 阅读
  3. python-基础(4)-list

    2024-04-25 22:42:01       33 阅读
  4. TypeScript 泛型类型

    2024-04-25 22:42:01       33 阅读
  5. 鸿蒙应用开发之Web组件4

    2024-04-25 22:42:01       28 阅读
  6. missing 1 required positional argument: ‘self‘

    2024-04-25 22:42:01       30 阅读
  7. 什么是SSRF?

    2024-04-25 22:42:01       25 阅读