大体逻辑
#这个是你选择的主机 - hosts: webservers #这个是变量 vars: http_port: 80 max_clients: 200 #远端的执行权限 remote_user: root tasks: #利用yum模块来操作 - name: ensure apache is at the latest version yum: pkg=httpd state=latest - name: write the apache config file template: src=/srv/httpd.j2 dest=/etc/httpd.conf #触发重启服务器 notify: - restart apache - name: ensure apache is running service: name=httpd state=started #这里的restart apache 和上面的触发是配对的。这就是handlers的作用。相当于tag handlers: - name: restart apache service: name=httpd state=restarted
#playbook.yml --- #顶行写 - hosts: webservers #顶行写 remote_user: root #两个空格 tasks: #两个空格 - name: whoami #四个空格 copy: src=~/hosts dest=~/hosts.dest #六个空格 notify: - clear copy #10个空格 handlers: #两个空格 - name: clear copy #四个空格 shell: 'mv ~/hosts.dest hosts.del' #六个空格
大体写yml的思路
主机: - hosts 用户 remote_user 变量 vars: 任务 tasks: 任务完成所需要做的东西:handlers
远程主机安装httpd并启动
--- - hosts: webservers remote_user: root vars: http_port: 80 max_clients: 200 tasks: - name: ensure apache is latest yum: pkg=httpd state=latest - name: runing service: name=httpd state=started
转载于:https://blog.51cto.com/wsxxsl/1837820