Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

hostvars['127.0.0.1']['ansible_system'] may not exist #739

Closed
dmitry-kulikov opened this issue Jun 13, 2017 · 5 comments · Fixed by #970
Closed

hostvars['127.0.0.1']['ansible_system'] may not exist #739

dmitry-kulikov opened this issue Jun 13, 2017 · 5 comments · Fixed by #970

Comments

@dmitry-kulikov
Copy link

Expected behavior:

Installation completed without errors.

Actual Behavior:

Installation completed with minor errors:

TASK [streisand-gateway : Attempt to open the instructions on Linux (if applicable). Errors in this task are ignored because the `xdg-open` command is not always available.] ***
fatal: [x.x.x.x]: FAILED! => {"failed": true, "msg": "The conditional check 'hostvars['127.0.0.1']['ansible_system'] == \"Linux\"' failed. The error was: error while evaluating conditional (hostvars['127.0.0.1']['ansible_system'] == \"Linux\"): 'dict object' has no attribute 'ansible_system'\n\nThe error appears to have been in '/media/veracrypt1/streisand/playbooks/roles/streisand-gateway/tasks/main.yml': line 199, 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: Attempt to open the instructions on Linux (if applicable). Errors in this task are ignored because the `xdg-open` command is not always available.\n        ^ here\n"}

Steps to Reproduce:

Run ./streisand.

Additional Details:

Really minor issue. I guess it should be fixed by replacing of

playbooks/roles/streisand-gateway/tasks/main.yml:202
- when: hostvars['127.0.0.1']['ansible_system'] == "Linux"
+ when: hostvars['127.0.0.1']['ansible_system'] is defined and hostvars['127.0.0.1']['ansible_system'] == "Linux"

and

playbooks/roles/streisand-gateway/tasks/main.yml:207
- when: hostvars['127.0.0.1']['ansible_system'] == "Darwin"
+ when: hostvars['127.0.0.1']['ansible_system'] is defined and hostvars['127.0.0.1']['ansible_system'] == "Darwin"
Target Cloud Provider: Scaleway
Operating System of target host: Ubuntu 16.04
Operating System of client: Ubuntu 14.04
Version of Ansible, using ansible --version : 2.3.1.0
@cpu
Copy link
Collaborator

cpu commented Jun 13, 2017

Hi @dmitry-kulikov,

I believe I've seen this error on my local machine as well and had meant to make a note to fix it. Thanks for reporting! It obviously slipped my mind 😆

I'd like to look into this a little bit deeper but won't have the time immediately. I'll try to have a fix posted in the next day or two. It should be safe to ignore this error in the mean time, you will just have to open the generated documentation yourself manually (which was probably already true if you are doing a localhost install on a remote server).

Thanks again!

@cpu
Copy link
Collaborator

cpu commented Jun 14, 2017

I was able to reproduce this on Archlinux with Ansible 2.3.1.0.

Really minor issue. I guess it should be fixed by replacing of
playbooks/roles/streisand-gateway/tasks/main.yml:202

  • when: hostvars['127.0.0.1']['ansible_system'] == "Linux"
  • when: hostvars['127.0.0.1']['ansible_system'] is defined and hostvars['127.0.0.1']['ansible_system'] == "Linux"

I think this will patch around the error but it won't result in Linux clients having the docs opened. I'd rather find a better solution if possible.

On my system I notice that there is no hostvars['127.0.0.1'] but there is a hostvars['localhost'] that has the correct ansible_system key. I suspect using hostvars['127.0.0.1'] will fix it for us but I'm nervous other systems will have the inverse problem (127.0.0.1 but no localhost).

@cpu
Copy link
Collaborator

cpu commented Jun 14, 2017

On my system I notice that there is no hostvars['127.0.0.1'] but there is a hostvars['localhost'] that has the correct ansible_system key. I suspect using hostvars['127.0.0.1'] will fix it for us but I'm nervous other systems will have the inverse problem (127.0.0.1 but no localhost).

Update: using "localhost" didn't help. I'm a bit stumped. It seems hostvars largely "pretends" to be a dict and there might be something else at work here. I'll have to revisit. Out of time for the night.

@cpu cpu added the status/help-wanted For items we'd love help with label Jul 4, 2017
@cpu cpu marked this as a duplicate of #806 Jul 14, 2017
@cpu cpu mentioned this issue Jul 14, 2017
cpu added a commit to cpu/streisand that referenced this issue Sep 16, 2017
Prior to this commit Streisand universally assumed the user's SSH
public key was `~/.ssh/id_rsa.pub`. This SSH key was then used to
provision cloud instances.

This commit adds a new `streisand_ssh_key` var to the
`global_vars/default-site.yml` file. The site-specific override for
these defaults, `~/.streisand/site.yml` is now customized by
`playbooks/customize.yml` when the user specifies that they want to use
a different SSH pubkey. The user is expected to have the private
component loaded into their ssh agent or to customize Ansible to know
how to load it.

The validation playbook is updated to check that the `streisand_ssh_key`
exists. The corresponding shell based checks for the SSH key were
removed from the `./streisand` wrapper script since they are now
replaced by these Ansible tasks. Similarly the existing server playbook
now performs its own quick test of a raw_cmd on the server instead of
doing a SSH check in the `./streisand` wrapper. This means things fail
a little bit later in the process if you can't actually SSH to the
existing server but it isn't *much* later in the process and its nice to
rm some shell script code.

Three unrelated bugs were fixed with the existing server provisioning.
First: There was a typo in the `./streisand` wrapper script's
`local_provision` function that was running a non-existent playbook.
Second: the genesis role was not being saved as a fact on localhost
causing the diagnostics to print "unknown" for the genesis role used.
Lastly, because no `gather_facts: yes` for the localhost was run for the
existing server provision other diagnostic information was missing. This
was also the root cause of Issue StreisandEffect#739. All of the above are now fixed!
Yay \o/
@cpu
Copy link
Collaborator

cpu commented Sep 16, 2017

I figured out the root cause of this bug while working on something separate. Serendipity!

The tl;dr is that the existing server flow never ended up running a gather_facts: true for localhost to populate hostvars.

I've fixed it as part of cpu@134e00a - I haven't opened a PR for this commit yet since it builds on top of #936 but I expect I will be able to merge it in the next week or so.

@cpu cpu removed the status/help-wanted For items we'd love help with label Sep 16, 2017
@cpu cpu closed this as completed in #970 Oct 14, 2017
cpu added a commit that referenced this issue Oct 14, 2017
Prior to this PR Streisand universally assumed the user's SSH private key was `~/.ssh/id_rsa`. The public component was then used to provision cloud instances.

This PR adds a new `streisand_ssh_private_key` var to the `global_vars/default-site.yml` file. The site-specific override for these defaults, `~/.streisand/site.yml` is now customized by `playbooks/customize.yml` when the user specifies that they want to use a different SSH key. The public component is expected to exist at the same file path with a `.pub` suffix to keep things simple.

This PR proactively sets the `ansible_ssh_private_key_file` for the Streisand  SSH key specified. This ensures Ansible will load & use this private key to access the streisand-host bypassing the need to use a ssh-agent (though it will play nicely if you do).

The validation playbook is updated to check that the  `streisand_ssh_private_key` exists. The corresponding shell based checks for the SSH key were removed from the `./streisand` wrapper script since they are now replaced by these Ansible tasks. Similarly the existing server playbook
now performs its own quick test of a raw_cmd on the server instead of doing a SSH check in the `./streisand` wrapper. This means things fail a little bit later in the process if you can't actually SSH to the existing server but it isn't *much* later in the process and its nice to `rm` some shell script code.

Two unrelated bugs were fixed with the existing server provisioning:  the genesis role was not being saved as a fact on localhost causing the diagnostics to print "unknown" for the genesis role used. Secondly, because no `gather_facts: yes` for the localhost was run for the existing server provision other diagnostic information was missing. This was also the root cause of Issue #739. 

Resolves #739, #300
@cpu
Copy link
Collaborator

cpu commented Oct 14, 2017

Should be all fixed in master by way of #970.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants