当前位置:网站首页>使用Ansible中的playbook
使用Ansible中的playbook
2022-07-26 05:07:00 【野124】
1.Playbook的功能
playbook 是由一个或多个play组成的列表,playboot 文件使用YAML来写的,playbooks是ansible更为强大的配置管理组件,实现基于文本文件编排执行的多个任务,且多次重复执行。. 其是使用YAML(Yet Another Markup Language),类似于半结构化语言,声明式配置,可读性较高。易于与脚本语言交互.
2.YAML
简介:是一种表达资料序列的格式,类似XML;Yet Another Markup Language,2001年首次发表,www.yaml.org
特点:可读性好,和脚本语言交互性号,易于实现,适用程序执行流梳理方式,可扩展性强
语法简介:
在文件中用[---]开始,在文件中用[...]结尾,次行一般书写文件内容,缩进严格,大小写敏感
key/value可以多行书写也可一行书写,一行书写用,(逗号)隔开,value可以是个字符串,也可是list,一个play需要包括name和tasks ,name 是描述,tasks 是动作,一个name只能包含一个task,扩展名称yml或者yaml
YAML 列表
[Linux,C++,Java,Python]
- Linux
- C++
- Java
- Python
YAML的字典
字典作用存放键值
name:westos
age:12
jobs:linux
{name: "westos", age: "12", jobs: "linux"}
playbook执行命令
ansible-playbook xxx.yml xx
--check 或者 -C 检测
--syntax-check check language
--list-hosts 列出hosts
--list-tags 列出tag
--list-tasks 列出task
--limit ip 指定执行主机
-v -vv 现实过程

Playbook的核心组件
name 可选,建议使用多用于说明
hosts 受控主机列表
tasks 任务,用与选择执行部分代码
vim 设定技巧
set nu
autocmd FileType yaml setlocal ai ts=2 sw=2
setlocal 设定当前文件
ai 自动退格对齐 auto indent
ts ab建长度为2空格 tabstop=2
sw 缩进长度为2 shiftwidth=2
et 把tab键变成空格 expandtab

使用vim编写Ansible-playbook更方便
基本示例:安装vsftpd,设置火墙,配置/etc/vsftpd/vsftpd.conf,使匿名用户可以访问
---
- name: vsftpd play
hosts: westos
tasks:
- name: install vsftpd
dnf:
name: vsftpd
state: present
- name: enable firewalld
firewalld:
zone: public
service: ftp
permanent: yes
state: enabled
immediate: yes
- name:
lineinfile:
path: /etc/vsftpd/vsftpd.conf
regexp: anonymous_enable=NO
line: anonymous_enable=YES
backrefs: yes
- name: restart vsftpd
service:
name: vsftpd
state: restarted
- name: start vsftpd
service:
name=vsftpd
state=started
enabled=yes

边栏推荐
- Ggjj, do you have a look at this problem? Does caching cause cross domain problems?
- CMD operation command
- 【Leetcode】493. Reverse Pairs
- Map making of environmental impact assessment based on remote sensing interpretation and GIS technology
- ABAP语法学习(ALV)
- Learn to map with nature medicine -- complex heat map
- 注解@Autowired如何自动装配
- Seata submits at details in two stages
- JVM第六讲:线上环境 FGC 频繁,如何解决?
- JVM第五讲:纵横数据如何应对洪峰推送
猜你喜欢

Principle of image nonlocal mean filtering

图像非局部均值滤波的原理

Redis solves the problem of oversold inventory

Interprocess communication

普林斯顿微积分读本02第一章--函数的复合、奇偶函数、函数图像

奥特学园ROS笔记--6

未来大气污染变化模拟

Date and time function of MySQL function summary

一次线上事故,我顿悟了异步的精髓

Icml2022 | imitation learning by evaluating the professional knowledge of the presenter
随机推荐
Add and modify the verification logic, and use -validation- to complete the group verification
Please elaborate on the implementation principle of synchronized and related locks
Axi protocol (4): signals on the Axi channel
LeetCode链表问题——203.移除链表元素(一题一文学会链表)
安装NCCL\mpirun\horovod\nvidia-tensorflow(3090Ti)
The landing of tdengine in the GPS and AIS scheduling of Zhongtian steel
Axi protocol (5): burst mechanism of Axi protocol
Mathematical modeling and optimization analysis based on general optimization software gams
Embedded sharing collection 21
Meta analysis [whole process, uncertainty analysis] method based on R language and meta machine learning
推荐必读:测试人员如何快速熟悉新业务?
Yolov5 implementation process - Directory
Unnamed Article 33
Five simple and practical daily development functions of chrome are explained in detail. Unlock quickly to improve your efficiency!
Seata submits at details in two stages
How to connect tdengine through idea database management tool?
测试用例评审如何开展
Practical technology of SWAT Model in simulation of hydrology, water resources and non-point source pollution
MySQL eight knowledge points: from getting started to deleting the database
Redis过期删除策略和内存淘汰策略