Объект ansible.vars.unsafe_proxy.AnsibleUnsafeText» не имеет атрибута «public_ip»

Почему эта задача (из лучший способ запуска экземпляров aws ec2 с доступный):

  - name: Add the newly created EC2 instance(s) to the local host group (located inside the directory)
    local_action: lineinfile 
                  dest="./hosts" 
                  regexp={{ item.public_ip }} 
                  insertafter="[webserver]" line={{ item.public_ip }}
    with_items: ec2.instances

создать эту ошибку?

TASK [Add the newly created EC2 instance(s) to the local host group (located inside the directory)] ********************************************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'public_ip'\n\nThe error appears to have been in '/Users/snowcrash/ansible-ec2/ec2_launch.yml': line 55, column 9, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n      - name: Add the newly created EC2 instance(s) to the local host group (located inside the directory)\n        ^ here\n"}

person Snowcrash    schedule 22.07.2017    source источник


Ответы (2)


проблема здесь

with_items: ec2.instances

Должен быть:

with_items: '{{ ec2.instances }}'

ec2 - это переменная, ссылающаяся на словарь, поэтому вам нужно будет ссылаться на нее с правильным синтаксисом.

person Akil    schedule 16.10.2017
comment
Спасибо!! Это помогло - person Souad; 22.05.2018

Помещать:

  - debug: msg="{{ ec2.instances }}"

перед этим кодом и проверьте, каково содержимое этой переменной. Это должен быть список словарей, в каждом из которых есть член public_ip, иначе вы получите сообщение, которое получаете.

person plesiv    schedule 22.07.2017
comment
Я запускаю 1 экземпляр. Есть переменная public_ip и у нее есть значение. - person Snowcrash; 23.07.2017