ansible learning

本文介绍了Ansible的特点,包括无需在被控机部署agent、基于SSH通讯、适用于400-500台服务器规模等。同时,文章还阐述了Ansible的架构,包括核心组件、inventory配置、通过模块管理远程机器。此外,详细列举了Ansible的常用模块,如ping、command、shell、script、copy、fetch、file等,并提及了playbook和role的概念,用于组织和复用自动化任务。
摘要由CSDN通过智能技术生成

ansible的特点:
1.被控机无需部署agent,轻量级;
2.主控机与被控机通过ssh协议通讯;
3.存在性能瓶颈,适用400-500台左右的服务器规模;
4.基于python开发的自动化工具,国内python开发者很多,所以可选择的模块很多;

ansible架构:
ansible是核心组件,被控机的信息配置在inventory,默认通过ssh(也可以是其他模块)连接被控机,通过模块管理被控机器。playbook是ansible的剧本,可以定义带业务逻辑的脚本,是yaml语言。

ansible基本配置:
1.如果使用ssh连接被控机,配置ssh key免密码认证,在交付服务器的时候,将主控机的公钥拷贝到服务器的ssh目录。
2.配置被控机的ssh,useDNS = no,GSSAPIAuthentication=no,加快ssh认证速度。
3.配置ansible的hostkeychecking = no,避免首次登陆被控机需要收入yes将ansible 的host key加入 know_hosts。

ansible常用模块:
0.-m ping,该模块不是icmp包的ping命令,是基于ssh的一个模块功能,能够ssh登陆,则返回pong;
1.-m command 基本的命令,如hostname,ip;
2.-m shell 对于命令组合,或者含有从定向,管道,美元符等特殊符号,shell能够很好支持,command不能;
3.-m script 如果要执行一个很长的脚本,script比shell好用;
4.-m copy 将一个文件上传到被控机;
5.-m fetch 将文件从被控机器拉取到主控机器;
6.-m file 对文件进行操作,如创建、删除等;
7.其他的模块,如hostname,cron,yum,service,user,group等等,其实都可以通过script来实现,实际在企业中,都是script模块,copy模块;
8.template可以比copy模块更加灵活,能够利用jinjia2语言,对通用的配置文件进行设置,做到每个被控机配置不一样的内容,template只能在playbook中使用;

playbook:
利用yaml语言,对模块进行带业务逻辑的调用;实际可以不用该功能;

role:
对playbook的通用功能(利用模块完成的功能)进行整合,供其他playbook文件调用,重复调用,代码复用率高,是函数的思想;include
vi testrole.yaml

ansible-playbook testrole.yaml

欢迎使用Markdown编辑器

你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。

新的改变

我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能,我们增加了如下几点新功能,帮助你用它写博客:

  1. 全新的界面设计 ,将会带来全新的写作体验;
  2. 在创作中心设置你喜爱的代码高亮样式,Markdown 将代码片显示选择的高亮样式 进行展示;
  3. 增加了 图片拖拽 功能,你可以将本地的图片直接拖拽到编辑区域直接展示;
  4. 全新的 KaTeX数学公式 语法;
  5. 增加了支持甘特图的mermaid语法1 功能;
  6. 增加了 多屏幕编辑 Markdown文章功能;
  7. 增加了 焦点写作模式、预览模式、简洁写作模式、左右区域同步滚轮设置 等功能,功能按钮位于编辑区域与预览区域中间;
  8. 增加了 检查列表 功能。

功能快捷键

撤销:Ctrl/Command + Z
重做:Ctrl/Command + Y
加粗:Ctrl/Command + B
斜体:Ctrl/Command + I
标题:Ctrl/Command + Shift + H
无序列表:Ctrl/Command + Shift + U
有序列表:Ctrl/Command + Shift + O
检查列表:Ctrl/Command + Shift + C
插入代码:Ctrl/Command + Shift + K
插入链接:Ctrl/Command + Shift + L
插入图片:Ctrl/Command + Shift + G

合理的创建标题,有助于目录的生成

直接输入1次#,并按下space后,将生成1级标题。
输入2次#,并按下space后,将生成2级标题。
以此类推,我们支持6级标题。有助于使用TOC语法后生成一个完美的目录。

如何改变文本的样式

强调文本 强调文本

加粗文本 加粗文本

标记文本

删除文本

引用文本

H2O is是液体。

210 运算结果是 1024.

插入链接与图片

链接: link.

图片: Alt

带尺寸的图片: Alt

居中的图片: Alt

居中并且带尺寸的图片: Alt

当然,我们为了让用户更加便捷,我们增加了图片拖拽功能。

如何插入一段漂亮的代码片

博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片.

// An highlighted block
var foo = 'bar';

生成一个适合你的列表

  • 项目
    • 项目
      • 项目
  1. 项目1
  2. 项目2
  3. 项目3
  • 计划任务
  • 完成任务

创建一个表格

一个简单的表格是这么创建的:

项目 Value
电脑 $1600
手机 $12
导管 $1

设定内容居中、居左、居右

使用:---------:居中
使用:----------居左
使用----------:居右

第一列 第二列 第三列
第一列文本居中 第二列文本居右 第三列文本居左

SmartyPants

SmartyPants将ASCII标点字符转换为“智能”印刷标点HTML实体。例如:

TYPE ASCII HTML
Single backticks 'Isn't this fun?' ‘Isn’t this fun?’
Quotes "Isn't this fun?" “Isn’t this fun?”
Dashes -- is en-dash, --- is em-dash – is en-dash, — is em-dash

创建一个自定义列表

Markdown
Text-to- HTML
Run Ansible playbooks to launch complex multi-tier applications hosted in public clouds Key Features Build your learning curve using Ansible Automate cloud, network, and security infrastructures with ease Gain hands-on exposure on Ansible Book Description Ansible has grown from a small, open source orchestration tool to a full-blown orchestration and configuration management tool owned by Red Hat. Its powerful core modules cover a wide range of infrastructures, including on-premises systems and public clouds, operating systems, devices, and services?meaning it can be used to manage pretty much your entire end-to-end environment. Trends and surveys say that Ansible is the first choice of tool among system administrators as it is so easy to use. This end-to-end, practical guide will take you on a learning curve from beginner to pro. You'll start by installing and configuring the Ansible to perform various automation tasks. Then, we'll dive deep into the various facets of infrastructure, such as cloud, compute and network infrastructure along with security. By the end of this book, you'll have an end-to-end understanding of Ansible and how you can apply it to your own environments. What you will learn Write your own playbooks to configure servers running CentOS, Ubuntu, and Windows Identify repeatable tasks and write playbooks to automate them Define a highly available public cloud infrastructure in code, making it easy to distribute your infrastructure configuration Deploy and configure Ansible Tower and Ansible AWX Learn to use community contributed roles Use Ansible in your day-to-day role and projects Who This Book Is For Learn Ansible is perfect for system administrators and developers who want to take their current workflows and transform them into repeatable playbooks using Ansible. No prior knowledge of Ansible is required. Table of Contents An Introduction to Ansible Installing and Running Ansible The Ansible Commands Deploying a LAMP stack Deploying WordPress Targeting Multiple Distributions The core network modules Moving to the Cloud Building out a cloud network Highly Available Cloud Deployments Building out a VMware deployment Ansible Windows Modules Hardening Your Servers Using Ansible and OpenSCAP Deploying WPScan and OWASP ZAP Introducing Ansible Tower and Ansible AWX Ansible Galaxy Next Steps with Ansible Assessments
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值