zhltom 发表于 2018-1-2 21:46:27

Ansible之playbooks

1、定义了执行的远程主机是 webservers组,这个组定义主机有(192.168.88.2,192.168.88.3)  
2、定义了变量,这个变量可以运用到我们模板文件中(nginx2.conf)
  
3、定义了远程主机执行任务的是用户root
  remote_usery也可用于各task中,支持通过sudo的方式在远程主机上执行任务,其可用于play全局后某任务;此外,设置可以在sudo时使用sudo_user指定sudo时切换的用户
  - hosts: webnodes
  remote_user: heboan
  tasks:
  - name: test connection
  ping:
  remote_user: heboan
  sudo: yes
  
4、任务列表:定义了5个任务
  ①create directory /data/www
  ②copy index.html
  ③install nginx is at the latest version
  ④start nginx
  ⑤write the nginx config file
  其中任务⑤是替换配置文件,我们都知道nginx配置文件变更需要重启才会生效,所以这里关联了一个的handlers
  
5、因为有关联操作,所以我们需要定义handlers
  
页: [1]
查看完整版本: Ansible之playbooks