![Ansible——有问题的一行似乎是:](https://linux22.com/image/777707/Ansible%E2%80%94%E2%80%94%E6%9C%89%E9%97%AE%E9%A2%98%E7%9A%84%E4%B8%80%E8%A1%8C%E4%BC%BC%E4%B9%8E%E6%98%AF%EF%BC%9A.png)
我正在尝试实施一个剧本来获取几个位置的外部 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