我正在尝试实施一个剧本来获取几个位置的外部 IP 地址,但它一直给我同样的错误:
The offending line appears to be:
remote_user: pi
tasks:
^ here
我把缩进弄乱了几次,但毫无效果。任何帮助都非常感谢,我对此很陌生,仍在学习,所以可能有些东西我遗漏了(下面的剧本)
- name: See if location is running on cradlepoint
hosts: cradlepoints
remote_user: pi
tasks:
- name: Grab External IP
dig:
- +short myip.opendns.com @resolver1.opendns.com
- name: Print a message
debug:
msg: 'Here Ya Go'
答案1
缩进错误,tasks
应与hosts
和在同一水平remote_user
。
- name: See if location is running on cradlepoint
hosts: cradlepoints
remote_user: pi
tasks:
- name: Grab External IP
dig:
- +short myip.opendns.com @resolver1.opendns.com
- name: Print a message
debug:
msg: 'Here Ya Go'
主要问题似乎是你使用dig
模块,与文档中描述的内容完全不同。它旨在用作查找模块。
- ansible.builtin.debug:
msg: "{{ lookup('community.general.dig', 'myip.opendns.com.')}}"
看起来您实际上正在尝试运行dig
shell 命令。
- shell: "dig +short myip.opendns.com @resolver1.opendns.com"
register: myip
- debug:
var: myip