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"

相关推荐
kebidaixu16 小时前
BCU 平台 RS485 驱动适配:从 THVD1406 到 ISO3082
linux
杨浦老苏17 小时前
家庭实验室监控仪表盘HomeLab-Monitor
运维·docker·监控·群晖
回忆2012初秋17 小时前
【Nginx】原理、配置与运维实战(2)
运维·nginx·策略模式
Urbano18 小时前
工装外套全制作流程、工序痛点及自动化设备升级方案
运维·自动化
映翰通朱工18 小时前
工业4G网关无公网IP远程运维实战(内网终端异地访问方案)
运维·服务器·网络·安全·智能路由器
洪晓露19 小时前
将 rke2 集群证书延长至 10 年
运维·服务器·数据库
谢平康19 小时前
解决用 rm 报bash: /usr/bin/rm: Argument list too long错
linux·运维·运维开发
IP老炮不瞎唠19 小时前
Python 价格监控如何实现?思路与实用方法分享
运维·服务器·网络
GIS数据转换器19 小时前
城市排水生命线安全运行监测平台深度解析
java·运维·人工智能·python·安全·数据挖掘·无人机
Tokai_Teio_120 小时前
第四届黄河流域 misc
运维·服务器