一、playbook 剧本介绍
playbooks 本身由以下各部分组成
(1)Tasks:任务,即通过 task 调用 ansible 的模板将多个操作组织在一个 playbook 中运行
(2)Variables:变量
(3)Templates:模板
(4)Handlers:处理器,当changed状态条件满足时,(notify)触发执行的操作
(5)Roles:角色
二、示例
vim /etc/ansible/playbook/deamo1.yml
---
- name: the first play for install apache
#gather_facts: false
hosts: dbservers
remote_user: root
tasks:
- name: disable firewwalld
service: name=firewalld state=stopped enabled=no
- name: disable selinux
command: '/usr/sbin/setenforce 0'
ignore_errors: True
- name: disable selinux forever
replace: path=/etc/selinux/config regexp="enforcing" replace="disabled"
- name: mount cdrom
mount: src=/dev/sr0 path=/mnt fstype=iso9660 state=mounted
- name: copy local yum configuration file
copy: src=/etc/yum.repos.d/repo.bak/local.repo dest=/etc/yum.repos.d/local.repo
- name: install apache
yum: name=httpd state=latest
- name: prepare httpd configuration