当前位置:网站首页>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 0fi
The 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.214
You 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
边栏推荐
- 云函数实现网站自动化签到配置详解【Web函数/Nodejs/cookie】
- 【正点原子STM32连载】第四章 STM32初体验 摘自【正点原子】MiniPro STM32H750 开发指南_V1.1
- 思想茶叶蛋 (Jul 31,2022)| 元宇宙(Metaverse)下了一枚什么样的蛋
- 速速脱单诀窍
- 【云驻共创】HCSD 大咖直播–就业指南
- 发现WRH几个表被锁了,怎么办?
- Detailed explanation of telnet remote login aaa mode [Huawei eNSP]
- 继承和static关键字
- Shared_preload_libraries导致很多语法不支持
- 蜜芽CEO刘楠:垂直电商黄金时代已落幕 坚定转型品牌之路
猜你喜欢
TiDB升级与案例分享(TiDB v4.0.1 → v5.4.1)
VRRP + MSTP configuration, huawei eNSP experiment 】 【
请你谈谈网站是如何进行访问的?【web领域面试题】
外包干了四年,秋招终于上岸了
【正点原子STM32连载】第三章 开发环境搭建 摘自【正点原子】MiniPro STM32H750 开发指南_V1.1
Implementation of redis distributed lock
DOM简述
yolo x 跑起来,详细的不行,且内含800错误解决办法
MindSpore:mirrorpad算子速度过慢的问题
Post-94 Byte P7 posted the salary slip: It's really good to make up for this...
随机推荐
今年37了,被大厂抢着要...
优炫数据库只有数据文件如何恢复
一道[CSCCTF 2019 Qual]FlaskLight的详解再遇SSTI
Interview at 14:00 in the afternoon, I came out at 14:08 with my head down, asking too much...
Four common methods of network attacks and their protection
DOM简述
LVGL的多语言转换工具--字体设置的好助手
他97年的,我既然卷不过他...
请你谈谈网站是如何进行访问的?【web领域面试题】
leetcode动态规划经典例题——53.最大子数组和
TiFlash 源码阅读(五) DeltaTree 存储引擎设计及实现分析 - Part 2
JSP基本语法
蘑菇书EasyRL学习笔记
加降息与BTC流动性事件策略研究
Grafana9.0发布,Prometheus和Loki查询生成器、全新导航、热图面板等新功能!
MindSpore:【mindinsight】【Profiler】用execution_time推导出来的训练耗时远小于真实的耗时
leetcode动态规划系列(求路径篇)
telnet远程登录aaa模式详解【华为eNSP】
Inheritance and the static keyword
今日睡眠质量记录71分