4

I'm trying to implement a playbook to grab the external IP address at a few locations but it keeps giving me this same error:

The offending line appears to be:

  remote_user: pi
   tasks:
        ^ here

I've messed around with the indentation a few times, to no avail. Any help is appreciated, I'm new to this and still learning so there may be something I'm missing (playbook below)

- 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'
Brian Lamb
  • 59
  • 1
  • 4

1 Answers1

4

The indendation is wrong, tasks should be on the same level as hosts and 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'

The main problem seems to be your usage of the dig module, which is nothing like what's documented. It's intended to be used as a lookup module.

  - ansible.builtin.debug:
      msg: "{{ lookup('community.general.dig', 'myip.opendns.com.')}}"

It looks like you were actually tring to run the dig shell command.

  - shell: "dig +short myip.opendns.com @resolver1.opendns.com"
    register: myip
  - debug:
      var: myip
Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89