当前位置:网站首页>Ansible deployment scripts - pro available without pit
Ansible deployment scripts - pro available without pit
2022-08-04 09:06:00 【IT rat】
Environment: centos7, Netcom
The script is as follows:
#!/bin/bash#function:ansible#author:tommypeng 20220801#####root judgment #####if[ "$USER" != "root" ]thenecho "Error: non-root user, insufficient privileges!"exit 0fi###############Firewall and SElinux############systemctl stop firewalld && systemctl disable firewalld && echo "Firewall is off"sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config && echo "close selinux"##############Network Test##############ping -c 3 www.baidu.comif[ $? = 0 ]thenecho "External network communication is good!"elseecho "Are you kidding me? There is no yarn installed on the net!"exit 1fi##############yum source configuration################yum install epel-release -ymv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak >> /dev/nullyum clean allrpm -Uvh http://mirrors.ustc.edu.cn/epel/epel-release-latest-7.noarch.rpmyum makecache##########ansible installation##########yum -y install ansible##########Host Group Configuration##########read -p "Please enter the name of the host group: " pporead -p "Please enter the IP of host 1: " wokaoread -p "Please enter the IP of host 2: " haoshuaisleep 5cat >> /etc/ansible/hosts << EOF[$ppo]$wokao$haoshuaiEOF###########Password-free login##########rm -rf /root/.ssh/* ##Clear existing key pairssh-keygen -N '' -f /root/.ssh/id_rsa ###Create a key pair (the verification code is empty)ssh-copy-id -i /root/.ssh/id_rsa.pub $wokaossh-copy-id -i /root/.ssh/id_rsa.pub $haoshuai ####pass public key##########test############ansible $ppo -m command -a 'ifconfig'if [ $? -eq 0 ];thenecho -e "\n\033[32m-----------------------------------------------\033[0m"echo -e "\033[32m test is successful ansible installation is successful!\033[0m"elseecho -e "\033[32m test failed Ansible installation failed, about to exit!"exit 0fiThe default host list contains two hosts. If you need to add other hosts after the deployment is complete, please edit the file /etc/ansible/hosts
Add the corresponding host's IP to your host list.
[[email protected] ~]# vim /etc/ansible/hosts# Ex 2: A collection of hosts belonging to the 'webservers' group## [webservers]##alpha.example.org## beta.example.org## 192.168.1.100## 192.168.1.110....[pxg]192.168.137.213192.168.137.214You must also configure password-free login, as follows:
ssh-copy-id -i /root/.ssh/id_rsa.pub host IP ###Send the public key to the newly added host, please note that you need to enter the root password of the newly added host, enter it as prompted, example:
[[email protected] ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.137.216/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"The authenticity of host '192.168.137.216 (192.168.137.216)' can't be established.ECDSA key fingerprint is SHA256: YejXn/pAjoOSNaOfxVO+TiBPp6JmHfZ5Z8nbiUN5m0U.ECDSA key fingerprint is MD5:b6:8d:e0:b0:08:5c:29:dc:df:2e:87:4e:51:e7:20:48.Are you sure you want to continue connecting (yes/no)? yes/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new [email protected]'s password:Number of key(s) added: 1Now try logging into the machine, with: "ssh '192.168.137.216'"and check to make sure that only the key(s) you wanted were added.Extended: How to write the host list:
[pxg]
192.168.137.155
192.168.137.162
The above means: the host group pxg contains the hosts of these two IPs
Define Nested Groups
This is done by creating a host group name with the suffix :children, for example:
[web]
web1.example.com
web2.example.com
[db]
db1.example.com
db2.example.com
[all:children]
web
db
The above example can be changed to
[web]
web[1:2].example.com
[db]
db[1:2].example.com
[webdb:children]
web
db
边栏推荐
- MindSpore:【AIR模型导出】导出时提示源码中select_op参数类型转换失败
- .NET深入解析LINQ框架(五:IQueryable、IQueryProvider接口详解)
- Anton Paar安东帕密度计比重计维修DMA35性能参数
- Grafana9.0发布,Prometheus和Loki查询生成器、全新导航、热图面板等新功能!
- MindSpore:Ascend运行出现问题
- 我和 TiDB 的故事 | TiDB 对我不离不弃,我亦如此
- Interview at 14:00 in the afternoon, I came out at 14:08 with my head down, asking too much...
- NAT/NAPT地址转换(内外网通信)技术详解【华为eNSP】
- After four years of outsourcing, the autumn recruits finally landed
- leetcode单调栈经典例题——最大矩形
猜你喜欢

grafana手册之可视化配置图表table
![[Punctuality Atom STM32 Serial] Chapter 3 Development Environment Construction Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1](/img/6f/c736a3404377961e92b3bd1b5ea90e.png)
[Punctuality Atom STM32 Serial] Chapter 3 Development Environment Construction Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1

张朝阳对话俞敏洪:谈宇宙、谈焦虑、谈创业、谈退休、谈人生

MindSpore:【mindinsight】【Profiler】用execution_time推导出来的训练耗时远小于真实的耗时

.NET深入解析LINQ框架(五:IQueryable、IQueryProvider接口详解)

Implementation of redis distributed lock
![Detailed explanation of switch link aggregation [Huawei eNSP]](/img/c2/f9797fe8b17a418466b60cc3dc50a1.png)
Detailed explanation of switch link aggregation [Huawei eNSP]

命里有时终须有--记与TiDB的一次次擦肩而过

Producer and Consumer Problems in Concurrent Programming

三层交换机配置MSTP协议详解【华为eNSP实验】
随机推荐
ShowMeAI —— Show u 三连
yuv420sp转jpg
将jpg图片转换成yuv420(NV12)数据文件
Quick tips for getting out of a single
如何从PG导入数据到kingbaseES
MindSpore:model.train中的dataset_sink_mode该如何理解?
leetcode二叉树系列(一)
The separation configuration Libpq is supported, speaking, reading and writing
No module named 'flask_misaka' has been resolved [BUG solution]
Wang Shuang's Assembly Language Chapter 4: The First Program
VRRP+MSTP配置详解【华为eNSP实验】
oracle sql multi-table query
Four common methods of network attacks and their protection
TiCDC迁移-TiDB到MySQL测试
低代码应用开发的五大好处
【Attention】Dual Attention(DANet) & Fully Attention(FLA)
tcp连接的细节
leetcode二叉树系列(二)
ISO14443A读卡流程(作为示例参考)
async - await