# task to get username/password from group\_vars

**URL:** <https://forum.ansible.com/t/task-to-get-username-password-from-group-vars/22811>\
**Category:** Ansible Project\
**Created:** [October 17, 2016, 9:52pm UTC](https://forum.ansible.com/t/task-to-get-username-password-from-group-vars/22811 "2016-10-17T21:52:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RK1](https://avatars.discourse-cdn.com/v4/letter/r/9f8e36/32.png) [@RK1](https://forum.ansible.com/u/RK1)\
**Post date:** [October 17, 2016, 9:52pm UTC](https://forum.ansible.com/t/task-to-get-username-password-from-group-vars/22811/1 "2016-10-17T21:52:40Z")

</div>

I have a pretty easy playbook to connect to a Juniper switch and provide me the show version output. All works when I place the username and password into the playbook no problem. What I would prefer to do is set the username and password in group\_vars/all and have the username and password read from there. Any tips? I can’t seem to get this going. I think I may need to pass along a hostvars but can’t seem to figure it out.

playbook:

- hosts: juniper  
gather\_facts: no  
connection: local

tasks:

- name: DEFINE PROVIDER  
set\_fact:  
hostinfo:  
host: “{{ inventory\_hostname }}”  
password: xxxxx  
username: admin
- debug: var=hostvars[inventory\_hostname]
- name: show command  
junos\_command:  
provider: “{{ hostinfo }}”  
commands:
- show version  
register: version
- debug: msg=“{{ version.stdout }}”

group\_vars/all  
username=admin

password=xxxxxx

---

<div class="post-metadata">

**Author:** ![Alexander\_H\_Laughlin](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@Alexander\_H\_Laughlin](https://forum.ansible.com/u/Alexander_H_Laughlin)\
**Post date:** [October 19, 2016, 10:42pm UTC](https://forum.ansible.com/t/task-to-get-username-password-from-group-vars/22811/2 "2016-10-19T22:42:47Z")

</div>

`

[duchess@cody:tmp] cat /etc/ansible/hosts

[juniper]

localhost

`

Make sure you have localhost in the juniper group in your inventory.

`

[duchess@cody:tmp] cat group\_vars/juniper

---

<div class="post-metadata">

**Author:** ![Alexander\_H\_Laughlin](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@Alexander\_H\_Laughlin](https://forum.ansible.com/u/Alexander_H_Laughlin)\
**Post date:** [October 19, 2016, 10:47pm UTC](https://forum.ansible.com/t/task-to-get-username-password-from-group-vars/22811/3 "2016-10-19T22:47:18Z")

</div>

I almost forgot. . .

It’s generally unsafe to store credentials in cleartext on your hard drive, so the documentation on the [Ansible Vault](http://docs.ansible.com/ansible/playbooks_vault.html) may also be of some use to you.
