Display variable value from command line?

554 views
Skip to first unread message

skinnedknuckles

unread,
Apr 10, 2015, 11:46:36 AM4/10/15
to ansible...@googlegroups.com
I'm suspicious that the variables in my windows.yml file are not being loaded properly.  Is there an easy way to display the values of current variables from the command line or do I need to write up a playbook to do this?

for example here is my windows.yml file

ansible_ssh_user: ansible
ansible_ssh_password: ansible123
ansible_ssh_port: 5986
ansible_connection: winrm

How can I check if these values were actually assigned to the variables?

Brian Coca

unread,
Apr 10, 2015, 12:52:08 PM4/10/15
to ansible...@googlegroups.com
you can create a template that dumps all variables or if you have a
short list you can use debug module:

- debug: var=ansible_ssh_user
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/809242f6-3502-4db2-b470-77263cdadd5f%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

Chris Church

unread,
Apr 10, 2015, 1:36:10 PM4/10/15
to ansible...@googlegroups.com
That won't quite work if it's actually picking up the ansible_connection=winrm variable.  WinRM actually connects in the connect() method of the connection plugin, whereas SSH doesn't try to establish a connection until later (see https://github.com/ansible/ansible/issues/10197).

The workaround to display the connection variables without actually trying is using a playbook like the following:

---

- hosts: windows
  gather_facts: false
  tasks:
    - local_action: debug var=ansible_connection


skinnedknuckles

unread,
Apr 25, 2015, 9:47:45 PM4/25/15
to ansible...@googlegroups.com
Okay this is fixed.  I've discovered that the values assigned to the variables in ansible\group_vars\windows.yml namely  "ansible_ssh_user" and "ansible_ssh_pass" must:
  1. Exactly match an account on the windows machine with admin privileges (account must exist but need NOT be current active login)
  2. If you are using SSL and the value of winrm/config/service/AllowUnencrypted is true (this is the default) the values in ansible\group_vars\windows.yml must exactly match the username and password that was submitted to generate the SSL web certificate. 
In my case I also had to append the computer name with the port number in the inventory like this

[windows]
ComputerName:5986 

(or 5985 for AllowUnedcrypted="true" type this command in powershell PS C:\winrm set winrm/config/service '@{AllowUnencrypted="true"}'

done.
Reply all
Reply to author
Forward
0 new messages