ansible-playbook模块shell,ansible-playbook
ansible-playbook模块shell,ansible-playbook
ansible-playbook 学习记录
使用ansible-playbook打印helloworld并重定向到日志文件
shell_demo.yml
方式一。将命令直接通过shell模块在playbook中执行
wfq@ubuntu:~/playbook$ cat shell_demo.yml
---
- hosts: asb
tasks:
- name: "demo shell"
shell: echo helloworld I love ansible > /home/wfq/playbook/pb.log
方式二。将命令写入shell脚本shell_demo_1.sh中,ansible-playbook执行shell脚本
wfq@ubuntu:~/playbook$ cat shell_demo_1.yml
---
- hosts: asb
tasks:
- name: "demo shell"
shell: sh /home/wfq/playbook/pb_shell.sh
wfq@ubuntu:~/playbook$
执行过程:
wfq@ubuntu:~/playbook$ ansible-playbook shell_demo.yml
PLAY [asb] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [192.168.174.133]
ok: [192.168.174.132]
ok: [192.168.174.131]
ok: [192.168.174.134]
TASK: [demo shell] ************************************************************
changed: [192.168.174.131]
changed: [192.168.174.134]
changed: [192.168.174.132]
changed: [192.168.174.133]
PLAY RECAP ********************************************************************
192.168.174.131 : ok=2 changed=1 unreachable=0 failed=0
192.168.174.132 : ok=2 changed=1 unreachable=0 failed=0
192.168.174.133 : ok=2 changed=1 unreachable=0 failed=0
192.168.174.134 : ok=2 changed=1 unreachable=0 failed=0
wfq@ubuntu:~/playbook$
查看日志执行结果:
wfq@ubuntu:~/playbook$ cat pb.log
helloworld I love ansible
wfq@ubuntu:~/playbook$
评论暂时关闭