【发布时间】:2020-01-10 15:40:58
【问题描述】:
我需要为远程主机设置日期,所以我读取本地主机日期然后需要获取ansible的hosts文件中定义的otherhost“ipv4_address”。
- hosts: localhost
become_user : root
tasks:
- name: align datetime
shell: |
data="$(date +'%Y/%m/%d +%H:%m:00')"
ssh user@{{ otherhost.ipv4_address }} "sudo date -s $data"
- hosts: otherhost
become: true
his tasks....
但这似乎不是获取 ipv4 的正确方法:
致命:[127.0.0.1]:失败! => {"msg": "任务包含一个选项 带有未定义的变量。错误是:“otherhost.ipv4_address”是 未定义\n\n错误似乎在
ansible --version
ansible 2.9.2
config file = None
configured module search path = ['/home/tec1/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/tec1/.local/share/virtualenvs/sniperx-EdPGXWMw/lib/python3.7/site-packages/ansible
executable location = /home/tec1/.local/share/virtualenvs/sniperx-EdPGXWMw/bin/ansible
python version = 3.7.3 (default, Apr 3 2019, 05:39:12) [GCC 8.3.0]
【问题讨论】:
标签: ansible