ansible playbook
#使用ansible-playbook 2.yml工具批量处理多任务
[root@host-***.***.***.*** ansible]# vim 2.txt # ({{hostname}} 下一行 {{port}})
{{hostname}}
{{port}}
▽
~
"2.txt" [New] 2L, 28C written
[root@host-***.***.***.*** ansible]# vim 2.vars #(hostname: master 下一行 port: 80)
hostname: master
port: 80
▽
~
~
~
~
"2.vars" [New] 2L, 22C written
[root@host-***.***.***.*** ansible]# vim 2.yml #(-代表下一级,所以不能跟上一行平行)
---
- hosts: all
vars_files:
- 2.vars
user: root
tasks:
- name: copy a file
template: src=‘2.txt‘ dest=‘/tmp/2.txt‘
~
~
"2.yml" 9L, 147C written
[root@host-***-***-***-*** ansible]# ansible-playbook 2.yml
[WARNING]: Found variable using reserved name: port
PLAY [all] ***************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************
ok: [***.***.***.***]
ok: [***.***.***.***]
TASK [copy a file] *******************************************************************************************************
changed: [***.***.***.***]
changed: [***.***.***.***]
PLAY RECAP ***************************************************************************************************************
***.***.***.*** : ok=2 changed=1 unreachable=0 failed=0
***.***.***.*** : ok=2 changed=1 unreachable=0 failed=0
[root@host-***-***-***-*** ansible]# ansible all -a "cat /tmp/2.txt"
***.***.***.*** | SUCCESS | rc=0 >>
master
80
***.***.***.*** | SUCCESS | rc=0 >>
master
80
本文出自 “13223089” 博客,请务必保留此出处http://13233089.blog.51cto.com/13223089/1958032
原文地址:http://13233089.blog.51cto.com/13223089/1958032