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"

相关推荐
石像鬼₧魂石19 小时前
内网渗透靶场实操清单(基于 Vulhub+Metasploitable 2)
linux·windows·学习·ubuntu
Danileaf_Guo19 小时前
256台H100服务器算力中心的带外管理网络建设方案
运维·服务器
橘子真甜~20 小时前
C/C++ Linux网络编程15 - 网络层IP协议
linux·网络·c++·网络协议·tcp/ip·计算机网络·网络层
拾贰_C21 小时前
【Linux | Windows | Terminal Command】 Linux---grep | Windows--- findstr
linux·运维·服务器
阿华hhh1 天前
Linux系统编程(标准io)
linux·开发语言·c++
虹科网络安全1 天前
艾体宝洞察 | 利用“隐形字符”的钓鱼邮件:传统防御为何失效,AI安全意识培训如何补上最后一道防线
运维·网络·安全
石像鬼₧魂石1 天前
Kali Linux 网络端口深度扫描
linux·运维·网络
alengan1 天前
linux上面写python3日志服务器
linux·运维·服务器
yBmZlQzJ1 天前
免费内网穿透-端口转发配置介绍
运维·经验分享·docker·容器·1024程序员节
JH30731 天前
docker 新手入门:10分钟搞定基础使用
运维·docker·容器