微网站主机注册免费,网站权重为零,昆山广告设计制作公司,如何禁止ip访问网站playbook#xff1a;
playbook#xff08;剧本#xff09;#xff1a;是ansible用于配置、部署和管理被控节点的剧本#xff0c;用于Ansible操作的编排。
使用的是yaml格式#xff0c;#xff08;saltstack、elk、docker、docker-compose、k8s都会使用到yaml格式。
playbook剧本是ansible用于配置、部署和管理被控节点的剧本用于Ansible操作的编排。
使用的是yaml格式saltstack、elk、docker、docker-compose、k8s都会使用到yaml格式。
这种格式对我们运维的人员还是非常重要的。 YAML格式
以.yaml结尾或者yml结尾。
1文件的第一行以---开始表明YAML文件的开始可选
2以#开头表示注释!-- --
3列表中的所有成员都开始于相同的缩进格式并以使用一个-作为开头。
4一个字典是由简单的 键 值 的形式组成冒号后面必须有一个空格。
注意的是写这种文件不要使用tab键都必须使用空格。我们正常使用两个空格。 看一个示例 字典和列表的格式 示例
[rootlocalhost playbook]# cat example.yaml
---
- hosts: group1remote_user: roottasks:- name: ensure apache is at the latest versionyum: namehttpd,httpd-devel statelatest- name: write the apache config filecopy: src/etc/httpd/conf/httpd.conf dest/etc/httpd/conf/httpd.confnotify:- restart apache- name: ensure apache is running (and enable it at boot)service: namehttpd statestarted enabledyeshandlers:- name: restart apacheservice: namehttpd staterestarted说明
1tasks任务。
2安装httpd
3copy模块同步配置文件
4notify是配置文件修改之后调用restart apache的handlers这种格式要留心下。 [rootlocalhost ~]# ansible-playbook /etc/ansible/playbook/example.yamlPLAY [group1] *************************************************************************************TASK [Gathering Facts] ****************************************************************************
ok: [192.168.17.106]
ok: [192.168.17.105]TASK [ensure apache is at the latest version] *****************************************************
changed: [192.168.17.105]
changed: [192.168.17.106]TASK [write the apache config file] ***************************************************************
changed: [192.168.17.105]
changed: [192.168.17.106]TASK [ensure apache is running (and enable it at boot)] *******************************************
changed: [192.168.17.105]
changed: [192.168.17.106]RUNNING HANDLER [restart apache] ******************************************************************
changed: [192.168.17.106]
changed: [192.168.17.105]PLAY RECAP ****************************************************************************************
192.168.17.105 : ok5 changed4 unreachable0 failed0 skipped0 rescued0 ignored0
192.168.17.106 : ok5 changed4 unreachable0 failed0 skipped0 rescued0 ignored0 说明绿色表示的没有更新。黄色的表示有更新。红色表示的failed。
步骤和错误都是可视化。这个是playbook的一个优点。 playbook有个专业术语幂等性。
幂等性的概念一次或多次请求某一个资源本身应该具有同样的结果。网络超时等问题除外。 1出错不用推导重做。
2剧本执行一百次结果只有一个。
3避免了万一出错需要重来的问题。我们可以先写个剧本万一某一步出错我们不需要推导重来。