ansible.vars.unsafe_proxy.AnsibleUnsafeText objek' tidak memiliki atribut 'public_ip'

Mengapa tugas ini (dari Cara terbaik untuk meluncurkan instance aws ec2 dengan mungkin):

  - 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

membuat kesalahan ini?

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 sumber


Jawaban (2)


masalahnya ada di sini

with_items: ec2.instances

Harus:

with_items: '{{ ec2.instances }}'

ec2 adalah variabel yang mereferensikan kamus sehingga Anda perlu mereferensikannya dengan sintaksis yang tepat

person Akil    schedule 16.10.2017
comment
Terima kasih!! Itu membantu - person Souad; 22.05.2018

Meletakkan:

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

sebelum kode itu dan periksa apa isi variabel itu. Itu harus berupa daftar kamus yang masing-masing memiliki anggota public_ip, jika tidak, Anda akan mendapatkan pesan yang Anda terima.

person plesiv    schedule 22.07.2017
comment
Saya meluncurkan 1 contoh. Ada variabel public_ip dan memiliki nilai. - person Snowcrash; 23.07.2017