Greetings.
I feel like I’ve done this before, but for some reason, I can’t figure it out.
I’ve got two hashes defined.
password_change:
cobbler: [ ebhpw ]
cougar: [ ehymowitz ]
password_groups:
ebhpw: ehymowitz
Then I’ve got a play.
- name: eric testing 9
debug:
msg: “it worked!!! variable is {{password_change.cobbler}}”
when:
- password_change.cobbler is defined
This works:
TASK [eric testing 9]
ok: [gs-444-e10285] => {
“msg”: “it worked!!! variable is [u’ebhpw’]”
}
I don’t fully understand what the brackets and the u are for. But I think that’s getting in my way. Because now I’m trying to do this:
- name: eric testing 9
debug:
msg: “it worked!!! variable is {{password_change.cobbler}}”
when:
- password_change.cobbler is defined
- password_groups[password_change.cobbler] is defined
and it fails.
TASK [eric testing 9]
skipping: [gs-444-e10285]
So what am I missing? It knows what password_change.cobbler is (“ebhpw”) , and it knows what password_groups[ebhpw] is (“ehymowitz”), so why I can’t I properly test for the value of password_groups[password_change.cobbler] ?
Thanks.
–EbH
Greetings.
I feel like I've done this before, but for some reason, I can't figure it
out.
I've got two hashes defined.
password_change:
cobbler: [ ebhpw ]
cougar: [ ehymowitz ]
If you don't understand the brackets, why are you using them here?
password_groups:
ebhpw: ehymowitz
Then I've got a play.
- name: eric testing 9
debug:
msg: "it worked!!!! variable is {{password_change.cobbler}}"
when:
- password_change.cobbler is defined
This works:
TASK [eric testing 9]
ok: [gs-444-e10285] => {
"msg": "it worked!!!! variable is [u'ebhpw']"
}
I don't fully understand what the brackets and the u are for.
List(array) in Ansible can be written in two ways.
myvar: ["one","two"]
or
myvar:
- one
- two
u is Pythons way of saying that the element in the list is unicode.
But I think
that's getting in my way. Because now I'm trying to do this:
Then you shouldn't use them in the first place.
- name: eric testing 9
debug:
msg: "it worked!!!! variable is {{password_change.cobbler}}"
when:
- password_change.cobbler is defined
- password_groups[password_change.cobbler] is defined
and it fails.
TASK [eric testing 9]
skipping: [gs-444-e10285]
So what am I missing? It knows what password_change.cobbler is ("ebhpw") ,
and it knows what password_groups[ebhpw] is ("ehymowitz"), so why I can't I
properly test for the value of password_groups[password_change.cobbler] ?
password_change.cobbler is not "ebhpw" it's list since you have the values between , but password_change.cobbler.0 does contain "ebhpw"
Thank you very much. That was the little push I needed. I think I've got it now.
--EbH