我创建了这个简单的脚本来调整所有机器上的时区,称为 date.sh
#!/bin/sh
# Exit at first error
set -e
# Set the localtime
timedatectl set-timezone Europe/Zurich
# Check date
date
我用 ansible 运行它
- name: Transfer and execute a script.
hosts: all
become_user: root
tasks:
- name: Transfer the script
copy: src=date.sh dest=/tmp/date.sh mode=0700
- name: Execute the script
command: sh /tmp/date.sh
可以,但是如何在 stdout 上查看输出?我试过了,但是出现错误。
- name: Transfer and execute a script.
hosts: all
become_user: root
tasks:
- name: Transfer the script
copy: src=date.sh dest=/tmp/date.sh mode=0700
- name: Execute the script
command: sh /tmp/date.sh
debug:
msg: "{{ test.stdout.split('\n') }}"