Make easyrsa_clients a dict if you really need a dict (remove the dash).
easyrsa_clients:
name: '{{ client }}'
- { src: '{{ easyrsa_dest }}/easyrsa/pki/private/{{
easyrsa_clients["name"] }}.key', dest: '{{ easyrsa_dest }}/keys' }
- { src: '{{ easyrsa_dest }}/easyrsa/issued/{{ easyrsa_clients["name"]
}}.crt', dest: '{{ easyrsa_dest }}/keys' }
I agree with Todd .. just use "client" if you have no other need to use
easyrsa_client.
Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123
On Nov 12, 2022, at 6:17 AM, Todd Lewis
<[email protected]<mailto:[email protected]>> wrote:
Oh, right, because "easyrsa_clients" is a list, not a dict.
So try it with either
- { src: '{{ easyrsa_dest }}/easyrsa/pki/private/{{ client }}.key', dest:
'{{ easyrsa_dest }}/keys' }
- { src: '{{ easyrsa_dest }}/easyrsa/issued/{{ client }}.crt', dest: '{{
easyrsa_dest }}/keys' }
or
- { src: '{{ easyrsa_dest }}/easyrsa/pki/private/{{
easyrsa_clients[0]["name"] }}.key', dest: '{{ easyrsa_dest }}/keys' }
- { src: '{{ easyrsa_dest }}/easyrsa/issued/{{ easyrsa_clients[0]["name"]
}}.crt', dest: '{{ easyrsa_dest }}/keys' }
or
- { src: '{{ easyrsa_dest }}/easyrsa/pki/private/{{
easyrsa_clients[0].name }}.key', dest: '{{ easyrsa_dest }}/keys' }
- { src: '{{ easyrsa_dest }}/easyrsa/issued/{{ easyrsa_clients[0].name
}}.crt', dest: '{{ easyrsa_dest }}/keys' }
But I suspect you have bigger plans. Why is easyrsa_clients a list? Do you
intend to add other clients later? In which case, the above isn't going to
work. you need something that will handle a fully articulated set of the data.
That's what I alluded to when I (mis)typed "Or is there more to the problem
than you've shown us?"
Do let us know how you get on.
On 11/11/22 9:48 PM, SysAdmin EM wrote:
Hello Todd, i try with
easyrsa_clients.name<https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Feasyrsa_clients.name%2F&data=05%7C01%7Cwalter.rowe%40nist.gov%7C912218e736214c51702708dac49f8138%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638038486598439571%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=rdeeXOOWsRtyfsiW8kqDy4AuksY9aOXzjNBRnMFUWhw%3D&reserved=0>
but i see this error:
TASK [Probando salida]
*****************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an
undefined variable. The error was: 'list object' has no attribute 'name'\n\nThe
error appears to be in
'/etc/ansible/openvpn/create_access_prod/playbook/list-test.yaml': line 6,
column 7, but may\nbe elsewhere in the file depending on the exact syntax
problem.\n\nThe offending line appears to be:\n\n tasks:\n - name:
\"Probando salida\"\n ^ here\n"}
PLAY RECAP
*****************************************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1
skipped=0 rescued=0 ignored=0
How can I use the name key in a with_items?
On Fri, Nov 11, 2022 at 11:24 PM Todd Lewis
<[email protected]<mailto:[email protected]>> wrote:
You can't use "item" inside "with_items:" because "item" is being defined by
"with_items:".
Why don't you just use "client":
- name: "Copy files
copy:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
with_items:
- { src: '{{ easyrsa_dest }}/easyrsa/pki/private/{{ client }}.key', dest:
'{{ easyrsa_dest }}/keys' }
- { src: '{{ easyrsa_dest }}/easyrsa/issued/{{ client }}.crt', dest: '{{
easyrsa_dest }}/keys' }
or
"easyrsa_clients.name<https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Feasyrsa_clients.name%2F&data=05%7C01%7Cwalter.rowe%40nist.gov%7C912218e736214c51702708dac49f8138%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638038486598439571%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=rdeeXOOWsRtyfsiW8kqDy4AuksY9aOXzjNBRnMFUWhw%3D&reserved=0>"?
Or is there more to the problem that you've shown us?
On 11/11/22 3:05 PM, SysAdmin EM wrote:
Hello, I hope you can understand what I need, my english is not good, i still
learning.
I have a variable
easyrsa_clients:
- name: '{{ client }}'
and this tasks:
- name: "Copy files
copy:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
with_items:
- { src: '{{ easyrsa_dest }}/easyrsa/pki/private/{{
item.name<https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fitem.name%2F&data=05%7C01%7Cwalter.rowe%40nist.gov%7C912218e736214c51702708dac49f8138%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638038486598439571%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=TKx1uvOUYp3HhB3gyrMC%2BSBDhU73CL%2BXhr9hPpwPc1Q%3D&reserved=0>
}}.key', dest: '{{ easyrsa_dest }}/keys' }
- { src: '{{ easyrsa_dest }}/easyrsa/issued/{{
item.name<https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fitem.name%2F&data=05%7C01%7Cwalter.rowe%40nist.gov%7C912218e736214c51702708dac49f8138%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638038486598439571%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=TKx1uvOUYp3HhB3gyrMC%2BSBDhU73CL%2BXhr9hPpwPc1Q%3D&reserved=0>
}}.crt', dest: '{{ easyrsa_dest }}/keys' }
I need to be able to interact with the value of the variable easyrsa_clients
within the parameter with_item.
I think I should use
easyrsa_clients.item.name<https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Feasyrsa_clients.item.name%2F&data=05%7C01%7Cwalter.rowe%40nist.gov%7C912218e736214c51702708dac49f8138%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638038486598439571%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=e7q%2Bo%2B51bdHAuOS9QkUxQUsk5VXgJbADB2KCP1LTYLk%3D&reserved=0>
but I don’t know.
Any ideas??
Regards
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
--
Todd
--
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
[email protected]<mailto:[email protected]>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/ea20a296-7113-11a8-9c44-17cd7f05065a%40gmail.com<https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2Fea20a296-7113-11a8-9c44-17cd7f05065a%2540gmail.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=05%7C01%7Cwalter.rowe%40nist.gov%7C912218e736214c51702708dac49f8138%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638038486598439571%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=9gLjE4n5JlaScBJy3RnZIvg2fEQ8rEmtGzlv5EIAFdk%3D&reserved=0>.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/AAAEF8AA-6593-41D7-BBA7-91E721CF90CA%40nist.gov.