RedHatGov / redhatgov.workshops

This is a collection of Ansible-deployed workshop environments. Use it in combination with the student workbook content, from the repo at https://github.com/RedHatGov/redhatgov.github.io
http://redhatgov.io
65 stars 73 forks source link

hostvars[inventory_hostname]['ec2_tag_Index'] not working #42

Open rafaeltuelho opened 6 years ago

rafaeltuelho commented 6 years ago

The expression hostvars[inventory_hostname]['ec2_tag_Index'] used in many places is not working... It appears this fact is not being returned in hostvars fact....

TASK [wetty : Copy cert.pem to Wetty dir] ***************************************************************************************************************************************
fatal: [redhatgovbr.0.redhatbr.io]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'ec2_tag_Index'\n\nThe error appears to have been in '/home/rsoares/workshops/RedHatGov/redhatgov.workshops/roles/wetty/tasks/main.yml': line 57, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n#-------------------------------------------------------\n- name: Copy cert.pem to Wetty dir\n  ^ here\n\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'dict object' has no attribute 'ec2_tag_Index'"}
    to retry, use: --limit @/home/rsoares/.ansible-retry/2_configure.retry
t-prinz commented 5 years ago

Just for reference, I am running into this as well:

TASK [wetty : Copy cert.pem to Wetty dir] ** fatal: [EduCauseTrey.tower.0.redhatgov.io]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'ec2_tag_Index'\n\nThe error appears to have been in '/home/tprinz/Documents/Projects/EduCause-2018-Ansible-Workshop/redhatgov.workshops/roles/wetty/tasks/main.yml': line 39, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n#-------------------------------------------------------\n- name: Copy cert.pem to Wetty dir\n ^ here\n"} fatal: [EduCauseTrey.tower.1.redhatgov.io]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'ec2_tag_Index'\n\nThe error appears to have been in '/home/tprinz/Documents/Projects/EduCause-2018-Ansible-Workshop/redhatgov.workshops/roles/wetty/tasks/main.yml': line 39, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n#-------------------------------------------------------\n- name: Copy cert.pem to Wetty dir\n ^ here\n"}

ajacocks commented 5 years ago

Interesting. What versions of boto and botocore are you using? What Ansible version, as well.

Thanks!

On Wed, Oct 24, 2018 at 9:36 AM t-prinz notifications@github.com wrote:

Just for reference, I am running into this as well:

TASK [wetty : Copy cert.pem to Wetty dir]


fatal: [EduCauseTrey.tower.0.redhatgov.io]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'ec2_tag_Index'\n\nThe error appears to have been in '/home/tprinz/Documents/Projects/EduCause-2018-Ansible-Workshop/redhatgov.workshops/roles/wetty/tasks/main.yml': line 39, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n#-------------------------------------------------------\n- name: Copy cert.pem to Wetty dir\n ^ here\n"} fatal: [EduCauseTrey.tower.1.redhatgov.io]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'ec2_tag_Index'\n\nThe error appears to have been in '/home/tprinz/Documents/Projects/EduCause-2018-Ansible-Workshop/redhatgov.workshops/roles/wetty/tasks/main.yml': line 39, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n#-------------------------------------------------------\n- name: Copy cert.pem to Wetty dir\n ^ here\n"}

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/RedHatGov/redhatgov.workshops/issues/42#issuecomment-432658495, or mute the thread https://github.com/notifications/unsubscribe-auth/AVdXcqd_EuoxntZKvCnNO-IirLrJ5r6Sks5uoGzBgaJpZM4VVlbG .

--

J. Alexander Jacocks | Senior Solutions Architect (e) alexander@redhat.com | Public Sector Business Development (c) (240) 447-5974 | Tyson's Corner, VA (g) CC28 8136 C253 907A B9BB 9EEA D3C8 1A3A 790A 0AB9

rafaeltuelho commented 5 years ago

I'm using on my Mac:

Python 2.7.15
Ansible 2.6.2
Terraform v0.11.10

pip list | grep boto
boto                          2.49.0
boto3                        1.7.72
botocore                   1.10.72

But, in order to get instances tag from ec2 I had to use this: https://github.com/rafaeltuelho/redhatgov.workshops/blob/redhatbr/roles/wetty/tasks/main.yml#L3-L10

and then I can use this: {{ hostvars[inventory_hostname].ec2_tags.tags.Index }}, like in https://github.com/rafaeltuelho/redhatgov.workshops/blob/redhatbr/roles/wetty/tasks/main.yml#L52

ajacocks commented 5 years ago

Rafael,

You might want to consider using something like this:

That pulls instance tags (you can see me filtering for tags, in the first task. See the "ansible_tower_aws" workshop for more information.

Does that make sense?

Thanks!

On Thu, Dec 6, 2018 at 9:12 AM Rafael T. C. Soares (A.K.A Tuelho) < notifications@github.com> wrote:

I'm using on my Mac:

Python 2.7.15 Ansible 2.6.2 Terraform v0.11.10

pip list | grep boto boto 2.49.0 boto3 1.7.72 botocore 1.10.72

But, in order to get instances tags from ec2 I had to use this: https://github.com/rafaeltuelho/redhatgov.workshops/blob/redhatbr/roles/LetsEncrypt/tasks/main.yml#L3-L12

and then I can use this: {{ hostvars[inventory_hostname].ec2_tags.tags.Index }}, like in https://github.com/rafaeltuelho/redhatgov.workshops/blob/redhatbr/roles/LetsEncrypt/tasks/main.yml#L46

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/RedHatGov/redhatgov.workshops/issues/42#issuecomment-444883448, or mute the thread https://github.com/notifications/unsubscribe-auth/AVdXch4CX0QBWDYNXB_lPAVQ6Sh6filnks5u2SXSgaJpZM4VVlbG .

--

J. Alexander Jacocks | Senior Solutions Architect (e) alexander@redhat.com | Public Sector Business Development (c) (240) 447-5974 | Tyson's Corner, VA (g) CC28 8136 C253 907A B9BB 9EEA D3C8 1A3A 790A 0AB9

rafaeltuelho commented 5 years ago

Thanks, @ajacocks ! I'll take a look at this approach. thanks.