自动化运维工具Ansible之Playbooks的when语句
# cat /etc/ansible/rewith.yml---
- hosts: webservers
remote_user: root
tasks:
- name: list of home dir
command: ls /home
register: home_dirs
- name: add home dirs to the backup
file: path=/tmp/back/{{ item }} src=/home/{{ item }} state=link
with_items: home_dirs.stdout_lines
# ansible-playbook /etc/ansible/rewith.yml
PLAY *************************************************************
GATHERING FACTS ***************************************************************
ok:
TASK: ******************************************************
changed:
TASK: *******************************************
changed: => (item=1.sql)
changed: => (item=1youku.sql)
changed: => (item=liuzhenwei)
changed: => (item=tom)
PLAY RECAP ********************************************************************
192.168.1.65 : ok=3 changed=2 unreachable=0 failed=0
###远程节点
# ll /tmp/back
total 0
lrwxrwxrwx. 1 root root 11 Aug4 14:37 1.sql -> /home/1.sql
lrwxrwxrwx. 1 root root 16 Aug4 14:37 1youku.sql -> /home/1youku.sql
lrwxrwxrwx. 1 root root 16 Aug4 14:37 liuzhenwei -> /home/liuzhenwei
lrwxrwxrwx. 1 root root9 Aug4 14:37 tom -> /home/tom
页:
[1]