当前位置:网站首页>Ansible的安装及部署
Ansible的安装及部署
2022-07-24 12:10:00 【野124】
实验环境:
1.设定克隆模板
2.克隆三台主机
3.开启三台设定主机的主机名,网络,确保三台主机能相互通信
4.在westos_ansible中设定共享软件仓库,安装epel源。确保可以列出ansible
1.Ansible对于企业运维的重大意义
Ansible是近几年越来越火的一款运维自动化工具,其主要功能是帮助实现IT工作的自动化、降低人为操作失误、提高业务自动化率、提升运维工作效率,Angible基于Python开发,而DevOps在国内已然是一种趋势, Python被逐步普及,运维人员自己开发工具的门槛逐步降低,得益于此,方便对Ansible二次开发。Ansible没有客户端,因此底层通信依赖于系统软件, Linux系统下基于OpenSSH通信, Windows系统下基于PowerShell,管理端必须是Linux系统
2.Ansible的安装
安装epel源
dnf install ansible -y
ansible --version

ansible的基本信息:
/etc/ansible/ansible.conf 全局配置文件,默认很少修改
/etc/ansible/hosts 全局主机清单清单文件
3.构建Anisble清单
清单就是ansible控制主机的列表
/etc/ansible/hosts 全局清单文件
清单查看:
ansible 清单中组名称 [-i 清单文件] --list-hosts
ansible ungrouped --list-hosts 列出没有设置清单名称的主机ip
ansible all --list-hosts 列出所有主机
单层清单
[westos]
192.168.43.203
192.168.43.204
[test1]
192.168.43.203
172.25.254.100
172.25.254.200
[test2]
192.168.43.204
172.25.254.200
嵌套清单
[testall:children]
test1
test2

测试:
ansible westos --list-hosts
ansible test1 --list-hosts
ansible test2 --list-hosts
ansible testall --list-hosts

通过指定主机名称或IP的范围可以简化Ansible主机清单
语法:vim /etc/ansible/hosts
[westostest]
192.168.43.[10:20]
测试: ansible westostest --list-hosts

vim /mnt/westos
[westos]
1.1.1.1
2.2.2.2
测试
ansible westos --list-hosts -i /mnt/westos

ansible命令指定清单的正则表达式
* 所有 192.168.43.* 在网段192.168.43中的所有主机
: 逻辑或 westos:test1 主机在westos清单中或者在test1清单中
:& 逻辑与 westos:&test2 主机即在westos清单也在test2清单中
:! 逻辑非 westos:!test2 在westos中不在test2中
~ 以关键字开头~(192|172) 以条件192或者条件172开头

4.Ansible配置文件参数详解
ansible 清单中组名称 -m 模块 -u remote_user
/etc/ansible/ansible.cfg 基本配置文件,找不到其他配置文件此文件生效
~/.ansible.cfg 用户当前目录中没有ansible.cfg此文件生效
./ansible.cfg 优先级最高
[defaults] 基本信息设定
inventory= 指定清单路径
remote_user= 在受管主机上登陆的用户名称,未指定使用当前用户
ask_pass= 是否提示输入SSH密码,如果公钥登陆设定为false
library= 库文件存放目录
local_tmp= 本机临时命令执行目录
remote_tmp= 远程主机临时py命令文件存放目录
forks= 并发数量
host_key_checking= 第一次连接受管主机时是否要输入yes建立host_key
sudo_user= 默认sudo用户
ask_sudo_pass= 每次在受控主机执行ansible命令时是否询问sudo密码
module_name= 默认模块,默认使用command,可以修改为shell
log_path= 日志文件路径
[privilege_escalation] 身份信息设定
become= 连接后是否自动切换用户
become_method= 设定切换用户的方式,通常用
sudo become_user= 在受管主机中切换到的用户,通常为root
become_ask_pass 是否需要为become_method提示输入密码,默认为false
5.构建用户级Ansible操作环境
在westso_ansible主机中建立用户useradd devops
设置密码echo westos | passwd –stdin devops
切换到用户su - devops
执行:ansible westos –m ping –u root -k
cd .asnible/
cp etc/devops/ansible.cfg .
vim /home/ansible/.ansible/ansible.cfg


ansible westos =m shell –a ‘useradd devops’ –u root –k
ansible westos –m shell –a ‘echo westos | passwd –stdin devops’ –u root -k
ansible westso –m shell –a‘echo“devopsALL=(ALL) NOPASSWD: ALL>>/etc/sudoers”’-uroot -k

免密认证
ansible westos –m file –a ‘path=/home/devops/.ssh owner=devops group=devops mode=0700 state=directory’ –u root

ansible westos –m copy –a ‘src=/home/devops/.ssh/id_rsa.pub dest=/home/devops/.ssh/auth
orized_keys owner=devops group=devops mode=0600’

vim /home/ansible/.ansible/ansible.cfg
用户级免密Ansible操作环境已创建成功
边栏推荐
- How to eliminate the character set and sorting rules specially set for fields in MySQL tables?
- 安装jmeter
- Import the data in MariaDB into columnstore
- Markdown mathematical formula syntax
- Understand what goals the MES system can achieve
- Browser logic vulnerability collection
- Collision, removal and cleaning
- Aruba learning notes 04 Web UI -- Introduction to configuration panel
- 计算两个坐标经纬度之间的距离(5种方式)
- Chapter 0 Introduction and environment configuration
猜你喜欢

Day3: branch structure

一周精彩内容分享(第13期)

L1-059 ring stupid bell
![[rust] rust language foundation | you should quickly get an impression when learning a language](/img/70/b420d62759f0c52bf4cc8d2a500813.png)
[rust] rust language foundation | you should quickly get an impression when learning a language

In kuborad graphical interface, operate kubernetes cluster to realize master-slave replication in MySQL

在kuborad图形化界面中,操作Kubernetes 集群,实现mysql中的主从复制
Learn some programming: anti unemployment "vaccine"

Source code analysis sentry user behavior record implementation process

Do you regret learning it?

Use prometheus+grafana to monitor server performance in real time
随机推荐
Chapter 0 Introduction and environment configuration
Guys, do you need to configure anything to use rocksdb when using flinksql? Or do you need any jar packages
String -- 344. Reverse string
TypeNameExtractor could not be found
基于ARM和FPGA的数字示波器设计——QMJ
Script redis write project notes
NFT digital collection system construction - app development
[rust] what software should I use to develop rust? Recommended editors commonly used to support rust
MES系统设备管理概述(中)
Wechat official account development: Material Management (temporary and permanent)
一周精彩内容分享(第13期)
CCF 201803_ 1 jump jump
PM's alarm: "NPM warn config global --global, --local are deprecated
L1-059 敲笨钟
Makefile quick use
Threat hunting collection
[I also want to brush through leetcode] 468. Verify the IP address
Optimization method of "great mathematics for use" -- optimal design of Cascade Reservoir Irrigation
AcWing 92. 递归实现指数型枚举
Miss waiting for a year! Baidu super chain digital publishing service is limited to 50% discount