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"

相关推荐
SelectDB29 分钟前
Apache Doris 在 AgentLogsBench 中领先,支撑 Agent 可观测性生产负载
运维·数据库·agent
荣-1 小时前
从两天到十几分钟:一套 YT Crash 自动化分析工具完整工程复盘
大数据·运维·自动化
酷炫的水壶1 小时前
使用memc-nginx和srcache-nginx模块构建高效透明的缓存机制
运维·nginx·缓存
dddwjzx2 小时前
嵌入式Linux C应用编程入门——信号
linux·嵌入式
范什么特西3 小时前
网络代理问题
java·linux·服务器
姚不倒3 小时前
F5 SSL Profile 证书卸载深入篇
运维·网络协议·负载均衡·ssl·f5
utf8mb4安全女神3 小时前
【Redis数据库】哨兵集群/redis集群/安装配置/主从复制/数据持久化操作/数据结构/安全限制/PHP redis/
linux·服务器·数据结构·数据库·redis·缓存
智商偏低3 小时前
Windows Nginx 完整安装 + 启动教程
运维·nginx
Zk.Sun4 小时前
Linux设置触屏双击距离容差
linux·运维·数据库
Let's Chat Coding4 小时前
对称密钥认证:主机和设备共享同一把密钥
运维·服务器·网络