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"

相关推荐
GeW2 小时前
超详细!RHCE10版通用备考策略,内含评分细则解读
linux
用户041328465133 小时前
Linux 服务开机自启动怎么配置?systemctl enable 原理详解
linux
草莓熊Lotso12 小时前
【Redis 初阶】Set 类型深度解析:去重集合的运算能力与实战场景
linux·网络·数据库·windows·redis·tcp/ip·缓存
张文君12 小时前
ubuntu26.04坏道坏块分区隔离急速版260831-V0.12
linux·python
IT大白鼠12 小时前
Docker 实战 ELKF 日志监控:容器日志全栈收集分析方案
运维·docker·容器
贝锐21 小时前
从国产化信创设备到商用安卓终端,向日葵如何帮助企业实现统一运维管理?
linux·运维·远程控制
Julien20041 天前
调查和解决 SELinux 问题
linux·运维·服务器·网络·学习方法
天远Date Lab1 天前
零信任架构实战:基于天远双人婚姻评估查询构建自动化房产按揭联合审查网关
运维·人工智能·架构·自动化
2601_962074681 天前
自己编译RustDesk,并将自建ID服务器和key信息写入客户端
运维·服务器
小张同学a.1 天前
Docker 容器实战 1—— docker 基础与镜像构建
linux·运维·docker·容器