The add hosts(droplets) to /etc/ansible/hosts directory isn't working. My script creates the droplets fine, but I can't add droplet ips to file

Viewed 16

Here is the script in question.

- name: save ip and hostname to local hosts file /etc/hosts
    become: yes
    lineinfile:
      dest: etc/ansible/hosts
      local_action: add_host hostname= "{{ item.droplets.ip_address }}" groupname= "{{ droplets }}"
    with_items: "{{ droplet_details.results }}"

And this is the error I get:

fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'droplets'\n\nThe error appears to be in '/etc/ansible/newplay.yml': line 44, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: save ip and hostname to local hosts file /etc/hosts\n ^ here\n"}

[localhost] TASK: save ip and hostname to local hosts file /etc/hosts (debug)> droplets ***NameError:NameError("name 'droplets' is not defined")

0 Answers
Related