Skip to content

Commit

Permalink
ansible_playbook
Browse files Browse the repository at this point in the history
  • Loading branch information
ppabc committed Jul 7, 2016
1 parent 4b5f0e2 commit 1524ebe
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions ansible/ansible_playbook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash
## ansible_playbook 2016-07-07
## http://www.aqzt.com
##email: [email protected]
##robert yu
##centos 6

##测试新建文件a.yml
- name: command
hosts: centos6
user: root
gather_facts: false
tasks:
- name: "cmd"
shell: touch /tmp/playbook.txt

#执行
ansible-playbook a.yml

##测试新建用户b.yml
- name: create user
hosts: centos6
user: root
gather_facts: false
vars:
- user: "xiaoyu"
tasks:
- name: create {{ user }}
user: name="{{ user }}"

#执行
ansible-playbook b.yml
#查看效果
ansible centos6 -m command -a "id xiaoyu"


##测试替换文件,再追加字符串 c.yml
- name: handlers test
hosts: centos7
user: root
tasks:
- name: test copy
copy: src=/etc/passwd dest=/tmp/handlers.txt
notify: test handlers
handlers:
- name: test handlers
shell: echo "test111" >> /tmp/handlers.txt

#执行
ansible-playbook c.yml





- hosts: centos7
user: root
tasks:
- name: change mode for files
file: path=/tmp/{{ item }} mode=600 owner=root group=root
with_items:
- 1.txt
- 2.txt


- hosts: centos7
user: root
gather_facts: True
tasks:
- name: use when
shell: touch /tmp/when.txt
when: facter_ipaddress == "192.168.10.132"






0 comments on commit 1524ebe

Please sign in to comment.