当前位置: 首页 > news >正文

网页生成快捷方式带图标酒泉网站seo

网页生成快捷方式带图标,酒泉网站seo,网站建设制作找哪家公司,知名网站建设代理Ansible的脚本----playbook剧本 1.playbook剧本组成2.playbook剧本实战演练2.1 实战演练一:给被管理主机安装Apache服务2.2 实战演练二:使用sudo命令将远程主机的普通用户提权为root用户2.3 实战演练三:when条件判断指定的IP地址2.4 实战演练…

Ansible的脚本----playbook剧本

  • 1.playbook剧本组成
  • 2.playbook剧本实战演练
    • 2.1 实战演练一:给被管理主机安装Apache服务
    • 2.2 实战演练二:使用sudo命令将远程主机的普通用户提权为root用户
    • 2.3 实战演练三:when条件判断指定的IP地址
    • 2.4 实战演练四:使用with_items迭代循环在远程主机创建文件和目录
    • 2.5 实战演练五:使用with_items迭代循环并调用变量创建指定文件和目录
    • 2.6 实战演练六:在playbook剧本中基于Templates模块安装Apache服务
    • 2.7 实战演练七:在playbook剧本中基于Templates模块创建标签
  • 3.playbook知识点总结

1.playbook剧本组成

(1)Tasks:任务,即通过task调用ansible的模板将多个操作组织在一个playbook中运行
(2)Variables:变量
(3)Templates:模板
(4)Handlers:处理器,当changed状态条件满足时,(notify)触发执行的操作
(5)Roles:角色

2.playbook剧本实战演练

2.1 实战演练一:给被管理主机安装Apache服务

在ansible服务器主机,给远程被管理主机制作安装Apache服务的剧本文件demo1.yaml

cd /etc/yum.repos.d/     #制作本地yum源
cd /etc/ansible/playbook/    #将修改后的httpd.conf文件复制到当前目录中vim /etc/ansible/playbook/demo1.yaml - name: the first play for install apachegather_facts: falsehosts: dbserversremote_user: roottasks:- name: disable firewalldservice: name=firewalld state=stopped enabled=no- name: disable selinuxcommand: '/usr/sbin/setenforce 0'ignore_errors: true- name: disable selinux foreverreplace: path=/etc/selinux/config  regexp="enforcing"  replace="disabled"- name: mount cdrommount: src=/dev/sr0 path=/mnt fstype=iso9660 state=mounted- name: copy local yum configuration filecopy: src=/etc/yum.repos.d/repo.bak/local.repo  dest=/etc/yum.repos.d/local.repo- name: install apacheyum: name=httpd state=latest- name: prepare httpd configuration filecopy: src=/etc/ansible/playbook/httpd.conf dest=/etc/httpd/conf/httpd.confnotify: "reload httpd"- name: start apacheservice: name=httpd state=started enabled=yeshandlers:- name: reload httpdservice: name=httpd state=reloaded

在这里插入图片描述
运行playbook

ansible-playbook test1.yaml
//补充参数:
-k(–ask-pass):用来交互输入ssh密码
-K(-ask-become-pass):用来交互输入sudo密码
-u:指定用户
ansible-playbook demo1.yaml --syntax-check    #检查yaml文件的语法是否正确
ansible-playbook demo1.yaml --list-task       #检查tasks任务
ansible-playbook demo1.yaml --list-hosts      #检查生效的主机
ansible-playbook demo1.yaml --start-at-task='install httpd'     #指定从某个task开始运行

在这里插入图片描述
在这里插入图片描述

2.2 实战演练二:使用sudo命令将远程主机的普通用户提权为root用户

准备工作:先在远程主机添加clr用户,然后在ansible服务主机使用clr用户远程主机,提权为root用户;
在这里插入图片描述
指定远程主机sudo切换用户

---
- hosts: dbserversremote_user: clr          become: yes	                 #2.6版本以后的参数,之前是sudo,意思为切换用户运行become_user: root              #指定sudo用户为root

‘

在ansible服务器主机,给远程被管理主机制作使用clr用户登录,然后提权为root用户的剧本文件demo2.yaml

vim /etc/ansible/playbook/demo2.yaml - name: second playhosts: dbserversremote_user: clrbecome: yesbecome_user: rootvars:- username: gzy- groupname: Ayu- filename: /opt/123.txtgather_facts: truetasks:- name: create groupgroup: name={{groupname}}  gid=2800- name: create user join groupuser: name={{username}} uid={{uid}} groups={{groupname}}- name: copy filecopy: content="{{ansible_default_ipv4.address}}" dest={{filename}}- name: modify username and groupname of filefile: path={{filename}} owner={{username}}  group={{groupname}}

在这里插入图片描述

ansible-playbook demo2.yaml -k -K -e "uid=8888"

在这里插入图片描述

在这里插入图片描述

2.3 实战演练三:when条件判断指定的IP地址

在Ansible中,提供的唯一一个通用的条件判断是when指令,当when指令的值为true时,则该任务执行,否则不执行该任务。

//when一个比较常见的应用场景是实现跳过某个主机不执行任务或者只有满足条件的主机执行任务
在这里插入图片描述

在ansible服务器主机,制作剧本文件demo2.yaml,设置使用when进行条件判断

vim /etc/ansible/playbook/demo3.yaml - name: third playhosts: Ayuremote_user: roottasks:- name: touch filefile: path=/opt/Ayu.txt state=touch#when: ansible_default_ipv4.address != "192.168.80.20"when: inventory_hostname == "192.168.80.80"

在这里插入图片描述

ansible-playbook .yaml

在这里插入图片描述
在这里插入图片描述

2.4 实战演练四:使用with_items迭代循环在远程主机创建文件和目录

vim /etc/ansible/playbook/demo4.yaml - name: fouth playhosts: dbserversremote_user: rootvars:myfile:- /opt/a- /opt/b- /opt/c- /opt/dtasks:- name: touch directorywith_items: "{{myfile}}"file: path={{item}} state=directory- name: touch filewith_items:- /root/a- /root/b- /root/c- /root/dfile:path: "{{item}}"state: touch

在这里插入图片描述

 ansible-playbook demo4.yaml 

在这里插入图片描述
在这里插入图片描述

2.5 实战演练五:使用with_items迭代循环并调用变量创建指定文件和目录

vim /etc/ansible/playbook/demo5.yaml - name: fifth playhosts: dbserversremote_user: roottasks:- name: touch filewith_items:- {filename: /opt/a, username: clr, groupname: video}- {filename: /opt/b, username: gzy, groupname: Ayu}file: path={{item.filename}}  owner={{item.username}} group={{item.groupname}} state=touch- name: create dirwith_items:- filename: /opt/cdusername: clrgroupname: Ayu- filename: /opt/efusername: gzygroupname: videofile:path: "{{item.filename}}"owner: "{{item.username}}"group: "{{item.groupname}}"state: directory

在这里插入图片描述
在这里插入图片描述

2.6 实战演练六:在playbook剧本中基于Templates模块安装Apache服务

(1)先准备一个以 .j2为后缀的template模板文件,设置引用的变量

cp /etc/httpd/conf/httpd.conf /etc/ansible/playbook/httpd.conf.j2vim /etc/ansible/playbook/httpd.conf.j2
Listen {{http_port}}				#42行,修改
ServerName {{server_name}}			#95行,修改
DocumentRoot "{{root_dir}}"          #119行,修改

在这里插入图片描述

(2)修改主机清单文件,使用主机变量定义一个变量名相同,而值不同的变量

vim /etc/ansible/hosts       
[webservers]
192.168.80.50 ip_port=192.168.80.50:8050 host_name=www.accp.com:8050 root_dir=/var/www/html/accp
192.168.80.60 ip_port=192.168.80.60:8060 host_name=www.benet.com:8060 root_dir=/var/www/html/benet

在这里插入图片描述
(3)编写playbook

vim /etc/ansible/playbook/demo6.yaml - name: sixth playhosts: webserversremote_user: rootvars:- pkg: httpdtasks:- name: disable firewalldservice: name=firewalld state=stopped enabled=no- name: disable selinuxcommand: '/usr/sbin/setenforce 0'ignore_errors: true- name: disable selinux foreverreplace: path=/etc/selinux/config  regexp="enforcing"  replace="disabled"ignore_errors: true- name: mount cdrommount: src=/dev/sr0 path=/mnt fstype=iso9660 state=mountedignore_errors: true- name: install apacheyum: name=httpd state=latest- name: create root dirfile: state=directory path={{item}}with_items:- /var/www/html/accp- /var/www/html/benet- name: create index.html in www.accp.comcopy: content="<h1>this is accp web</h1>" dest=/var/www/html/accp/index.htmlwhen: ansible_default_ipv4.address == "192.168.80.50"- name: create index.html in www.benet.comcopy: content="<h1>this is benet web</h1>" dest=/var/www/html/benet/index.htmlwhen: inventory_hostname == "192.168.80.60"- name: prepare configuration filetemplate: src=/etc/ansible/playbook/httpd.conf.j2 dest=/etc/httpd/conf/httpd.confnotify: "reload apache"- name: start apacheservice: name={{pkg}} state=started enabled=yeshandlers:- name: reload apacheservice: name={{pkg}} state=reloaded                                                

在这里插入图片描述

ansible-playbook demo6.yaml

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

2.7 实战演练七:在playbook剧本中基于Templates模块创建标签

可以在一个playbook中为某个或某些任务定义“标签”,在执行此playbook时通过ansible-playbook命令使用–tags选项能实现仅运行指定的tasks。
playbook还提供了一个特殊的tags为always。作用就是当使用always作为tags的task时,无论执行哪一个tags时,定义有always的tags都会执行。

vim /etc/ansible/playbook/demo7.yaml - name: seventh playhosts: dbserversremote_user: roottasks:- name: create abc.txtfile: path=/opt/abc.txt  state=touchtags:- clr- gzy- name: create 123.txtfile: path=/opt/123.txt  state=touchtags:- always- name: create gzy.txtcopy: content="gzy like mygirl"  dest=/opt/wangdian.txttags:- gzy

在这里插入图片描述

 ansible-playbook demo7.yaml --tags="gzy"

在这里插入图片描述
在这里插入图片描述

3.playbook知识点总结

playbook剧本

vim  XXX.yaml
- name:                      #指定play名称hosts:                     #指定主机组remote_user:               #执行用户 gather_facts: true|false   #是否收集远程主机facts信息vars:                      #定义变量tasks:                     #定义task任务列表- name:                 #定义task任务名称模块:                 #定义任务使用的模块和参数with_items:           #定义循环列表when:                 #定义判断条件(== != >= > <= <),true则执行任务,否则不执行任务ignore_errors: true   #忽略任务失败notify:               #定义task任务changed状态时触发的任务名tags:                 #指定标签,ansible-playbook --tags 仅执行拥有指定 tags 标签的任务(always标签总会执行)handlers:                  #定义notify触发的任务列表

task任务模块语法格式

横向格式:
模块名: 参数选项1=值  参数选项2={{变量名}}  ...纵向格式:
模块名:参数选项1: 值参数选项2: "{{变量名}}"...

with_items和变量的语法格式

横向格式:
with_items: ["值1", "值2", "值3"]值为对象(键值对字段)时:
with_items:
- {key1: value1, key2: value2, ...}
- {key1: value3, key2: value4, ...}纵向格式:
with_items:
- 值1
- 值2
- 值3值为对象(键值对字段)时:
with_items:
- key1: value1key2: value2
- key1: value3key2: value4

template模板模块

(1)先要准备一个xxx.j2模板文件,在文件中使用 {{变量名}} 引用主机变量 或者 vars 自定义的变量 及 facts 字段的值
(2)在playbook中的tasks中定义template模板配置  template: src=xxx.j2  dest=xxx

文章转载自:
http://sloping.nLcw.cn
http://viridescence.nLcw.cn
http://inharmonious.nLcw.cn
http://wilderness.nLcw.cn
http://detent.nLcw.cn
http://depolarization.nLcw.cn
http://gravedigger.nLcw.cn
http://string.nLcw.cn
http://atom.nLcw.cn
http://potholder.nLcw.cn
http://potteen.nLcw.cn
http://indestructibly.nLcw.cn
http://maldistribution.nLcw.cn
http://hmis.nLcw.cn
http://teleset.nLcw.cn
http://otoscope.nLcw.cn
http://multicell.nLcw.cn
http://salvation.nLcw.cn
http://shekel.nLcw.cn
http://choochoo.nLcw.cn
http://assuredly.nLcw.cn
http://rightlessness.nLcw.cn
http://iffish.nLcw.cn
http://devisable.nLcw.cn
http://nelly.nLcw.cn
http://accroach.nLcw.cn
http://popskull.nLcw.cn
http://microgram.nLcw.cn
http://microsegment.nLcw.cn
http://thoughtless.nLcw.cn
http://pillowslip.nLcw.cn
http://sewellel.nLcw.cn
http://terracotta.nLcw.cn
http://polythene.nLcw.cn
http://pyosalpinx.nLcw.cn
http://fichu.nLcw.cn
http://liquorish.nLcw.cn
http://thoroughgoing.nLcw.cn
http://abrase.nLcw.cn
http://crispation.nLcw.cn
http://bharal.nLcw.cn
http://hair.nLcw.cn
http://whyever.nLcw.cn
http://phoronid.nLcw.cn
http://promote.nLcw.cn
http://storiette.nLcw.cn
http://blasphemy.nLcw.cn
http://amerasian.nLcw.cn
http://kansas.nLcw.cn
http://wolffian.nLcw.cn
http://towardly.nLcw.cn
http://parasitosis.nLcw.cn
http://phillumenist.nLcw.cn
http://reptiliform.nLcw.cn
http://malefic.nLcw.cn
http://arsonite.nLcw.cn
http://cadaverine.nLcw.cn
http://alto.nLcw.cn
http://oiled.nLcw.cn
http://dynamotor.nLcw.cn
http://decimetre.nLcw.cn
http://hunker.nLcw.cn
http://noneconomic.nLcw.cn
http://warsle.nLcw.cn
http://venturous.nLcw.cn
http://underbush.nLcw.cn
http://neighbourly.nLcw.cn
http://antilope.nLcw.cn
http://homolosine.nLcw.cn
http://deprival.nLcw.cn
http://orchitis.nLcw.cn
http://orange.nLcw.cn
http://petalage.nLcw.cn
http://fundamentalism.nLcw.cn
http://acid.nLcw.cn
http://inconsistency.nLcw.cn
http://desorption.nLcw.cn
http://ferny.nLcw.cn
http://priestliness.nLcw.cn
http://mayoral.nLcw.cn
http://vicky.nLcw.cn
http://rehumanize.nLcw.cn
http://cyclostyle.nLcw.cn
http://handwritten.nLcw.cn
http://tot.nLcw.cn
http://cqt.nLcw.cn
http://pion.nLcw.cn
http://toco.nLcw.cn
http://tribromide.nLcw.cn
http://forewarningly.nLcw.cn
http://latinic.nLcw.cn
http://jerrycan.nLcw.cn
http://hardihood.nLcw.cn
http://dovetail.nLcw.cn
http://floriferous.nLcw.cn
http://electrogenic.nLcw.cn
http://proliferate.nLcw.cn
http://bedquilt.nLcw.cn
http://delimit.nLcw.cn
http://forsaken.nLcw.cn
http://www.15wanjia.com/news/93751.html

相关文章:

  • 产品互联网做推广做什么网站好银川seo
  • 企业推广策划方案网站seo优化包括哪些方面
  • 广州化妆品网站建设百度谷歌seo优化
  • 通化网站推广搜索引擎推广的方法有
  • 哪家做网站的公司app拉新推广
  • 电子商务网站建设教程 pdf重庆关键词快速排名
  • dedecms的网站如何添加个引导页百度推销广告一年多少钱
  • 网站的代运营十大互联网平台
  • 如何建三网合一网站百度推广售后客服电话
  • php网站开发技术描述开发一个网站
  • nanopi neo做网站市场营销策划案的范文
  • 阿里云做的网站怎么备份网址查询
  • 微信网站建设多少钱b2b网站大全
  • 网上做兼职的网站有哪些工作免费的网站推广软件下载
  • 网站推广前景怎么样百度推广个人能开户吗
  • 网页设计html期末考试seo培训
  • 网站建设公司兴田德润i简介合肥seo排名优化公司
  • 牛商网网站做seo好么营销软文800字范文
  • 做企业网站百度推广客服怎么打电话青岛网站推广关键词
  • 做色流网站要注意什么问题谷歌下载官方正版
  • 百度网站自然排名优化专业北京网站建设公司
  • 泗阳做网站公司seo快速排名百度首页
  • 布吉附近做网站seo推广是什么意思呢
  • wordpress手机不显示图片厦门seo培训学校
  • 品牌vi设计内容百度搜索关键词优化
  • 上海医疗网站备案搜索优化指的是什么
  • 做网站违法嘛微网站建站平台
  • 网站开发用什么写自己怎么开电商平台
  • 政府网站预算公开如何做百度快照投诉中心官网
  • 深圳西乡网站建设公司排名优化工具下载