Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Ansible 2.4? #1

Open
dverdin opened this issue Oct 18, 2017 · 3 comments
Open

Problem with Ansible 2.4? #1

dverdin opened this issue Oct 18, 2017 · 3 comments

Comments

@dverdin
Copy link

dverdin commented Oct 18, 2017

Hi Pieter,
I tried running ansible-tools with a freshly installed ansible 2.4.0.0 and the playbook fails quite soon. It's as if ansible did no explore the host_vars dirctory in the environment (see output below).
I've been searching for quite some time but did not find how to fix it.
Do you have any idea?

$ ansible-playbook site.yml -i environments/vm/inventory

[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and make sure become_method is 'sudo' (default). This feature will be removed in version 2.6. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
[DEPRECATION WARNING]: The use of 'include' for tasks has been deprecated. Use 'import_tasks' for static inclusions or 'include_tasks' for dynamic inclusions. This feature will be removed in a future release. Deprecation warnings can be 
disabled by setting deprecation_warnings=False in ansible.cfg.
[DEPRECATION WARNING]: include is kept for backwards compatibility but usage is discouraged. The module documentation details page may explain more about this rationale.. This feature will be removed in a future release. Deprecation 
warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
 ____________________________________
< PLAY [Configuration for all nodes] >
 ------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

 _____________________________________________
< TASK [common : Set /etc/hostname to dev-vm] >
 ---------------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

fatal: [dev-vm]: FAILED! => {"failed": true, "msg": "The field 'remote_user' has an invalid value, which includes an undefined variable. The error was: 'ansible_remote_user' is undefined

The error appears to have been in '/home/verdin/tmp/ansible-tools/roles/common/tasks/main.yml': line 3, column 3, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be


- name: Set /etc/hostname to {{ inventory_hostname }}
  ^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes.  Always quote template expression brackets when they
start a value. For instance:

    with_items:
      - {{ foo }}\n\nShould be written as:

    with_items:
     - \"{{ foo }}\"

exception type: <class 'ansible.errors.AnsibleUndefinedVariable'>
exception: 'ansible_remote_user' is undefined"}
	to retry, use: --limit @/home/verdin/tmp/ansible-tools/site.retry
 ____________
< PLAY RECAP >
 ------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

dev-vm                     : ok=0    changed=0    unreachable=0    failed=1   

@dverdin
Copy link
Author

dverdin commented Oct 18, 2017

It looks like options to designate environments changed in 2.4: https://docs.ansible.com/ansible/2.4/porting_guide_2.4.html#inventory
Weirdly enough, if I replace
ansible-playbook site.yml -i environments/vm/inventory
with:
ansible-playbook site.yml -i environments/vm
The playbook goes further, though it fails later.

@pmeulen
Copy link
Owner

pmeulen commented Oct 19, 2017

Hi David,

I haven't upgraded to 2.4 yet, still on 2.3. Your diagnosis regarding inventory seems correct. I'll have a look. Ideally I'd like to find a solution the works with both 2.3 and 2.4.

Regarding the error at name: Set /etc/hostname to {{ inventory_hostname }} it could be that the use of unquoted "{{ }}" is throwing it of. This is a pre 2.0 construction and much has changed (and improved) in the Ansible parser. Try changing this to name: "Set /etc/hostname to {{ inventory_hostname }}", or removing the "{{ }}" altogether. It's just the name of the task, it could be anything.

@dverdin
Copy link
Author

dverdin commented Oct 19, 2017

thanks for your answer Pieter!
Yes, trying to find a solution that will fit all ansible versions is wise.

Actually, about the unquoted "{{}}", the doc explains that quotes are mandatory when a value starts with a brace to make sure we're not starting a dictionary at this place in YAML.
Otherwise, using unquoted braces is fine.
For example :

vars:
  key: "{{my-var}}"

or

vars:
  key: This is {{my-var}}

are fine, whereas:

vars:
  key: {{my-var}}

is wrong.

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

No branches or pull requests

2 participants