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"

相关推荐
Nerd Nirvana1 小时前
软考—系统架构设计(案例 | 论文)
linux·系统架构·软件工程·软考·计算机基础
勤奋的凯尔森同学2 小时前
webmin配置终端显示样式,模仿UbuntuDesktop终端
linux·运维·服务器·ubuntu·webmin
希忘auto5 小时前
详解Redis在Centos上的安装
redis·centos
技术小齐6 小时前
网络运维学习笔记 016网工初级(HCIA-Datacom与CCNA-EI)PPP点对点协议和PPPoE以太网上的点对点协议(此处只讲华为)
运维·网络·学习
ITPUB-微风6 小时前
Service Mesh在爱奇艺的落地实践:架构、运维与扩展
运维·架构·service_mesh
打不了嗝 ᥬ᭄6 小时前
Linux的权限
linux
落幕7 小时前
C语言-进程
linux·运维·服务器
深度Linux7 小时前
C++程序员内功修炼——Linux C/C++编程技术汇总
linux·项目实战·c/c++
chenbin5207 小时前
Jenkins 自动构建Job
运维·jenkins
java 凯7 小时前
Jenkins插件管理切换国内源地址
运维·jenkins