Hi,

I do something similar..

users:

  - user_name: user1

    user_uid: 667

    user_key: "https://URL-TO-KEY-/user1/id_rsa.pub";

    

  - user_name: user2

    user_group: wheel

    user_key: "https://URL-TO-KEY-/user2/id_rsa.pub";


This way you can iterate over add user with same object users


 TASK

Let Add Keys for the users defined in group_vars/users

    - name: addd authorized_keys for users

      authorized_key:

        user: "{{ item.user_name }}"

        state: present

        key: "{{ item.user_key }}" 

      with_items: "{{users}}"

      

On Friday, March 23, 2018 at 11:18:19 AM UTC-7, Dayton Jones wrote:
>
> I have 2 separate dictionaries that I need to iterate over to 1) create a 
> user and 2) add their ssh keys (some users might have multiple keys)
> The first task works, the second...not so much - I've tried so many 
> things, I can't even remember (with_subelements, with_items, lookups, 
> etc).   How would I iterate over the 2 dictionaries to properly add the 
> correct key(s) to each user created in the first task?  I know it would 
> easier to combine the 2 dictionaries, but (for reasons) I can't at this 
> time.
>
> ---
> - name: Create Users
>   become: yes
>   user:
>     name: "{{ item }}"
>     shell: /bin/bash
>     state: present
>   with_items:
>     - "{{ ssh_users }}"
> - name: Accept public keys for Users
>   become: yes
>   authorized_key:
>     state: present
>     user: ????????
>     manage_dir: yes
>     exclusive: yes
>     key: ??????
>
>
>
>
> ssh_users:
>   - user1
>   - user2
>   - user3
>
> public_ssh_keys:
>   user1:
>     - "ssh-rsa 
> H*ogAtiwigE!YMESuneza7ahU3YXeWYGorEny2E6A2o8AzEmy@uraVaXEHUWy5AgiVe7oME7erE2eQE5owYQu&oju4a=usU+U8UBYHA1Uga*iPEpoqy5yzADijA=upy%iseREMaTa=i4UpUWi!A6EqaViJUQo2EsEwyqepejYjebytEbo5UruGYrEtEdY2o6ipe@U1EgoWiRyqa%ovUbYSugy7igabe*owiqezUDe1y=AMo!i6Ypa*iQe7oQAVYjE7opomEwUqY=izEDuxiwE=yZYQinoMY@eQY+ehaGo8ubEhuNabiPYvuXenEZara!iseMaTEnu4yQU@eMoJExULy*E=o%YzUSe3ydUDuveTEQomy5Y5YL
>  
> user1"
>   user2:
>     - "ssh-rsa 
> gHuLEniHa8UHU2ugu@UZovU+o6U*ANiwuNE8ERA!E6yPEDaTi!eNixY7obeMEQaGajE1e7a5ENAbUNy4o&yveQo=agExyLa6u6ERAzigyZyza2u3eGE@oNi+a*Y3yse!i+E8yREQoGU4UtUVEnE8A4Y6aWA8E8E4eBA&oZuRaqixEDi+uHeLyHETYVisatAtEzotE4a@A&UmehuLuDAQeMoxuxy5YDyVi5Ysy=uQYBYtaSaSoME+yZoBUWadAPeMoHa*iMo7Uru&U&Eja3ESAgUbUvequgEZiWa4oGuZusAzULaGuZyVabe6o&y7epUpojo2APu*eQeXaGomYnA&ehY2iSeRA+Y+yRUZa%i&udu@azEzE7A2
>  
> user2"
>   user3:
>     - "ssh-rsa 
> pynU!iRUVesU+eQubARyRY7uSojyJA&A1ASa%YgUhiSidU6eXUgA*Ube+YTERy%o*U%i=yMiGyQYji4u8otohy8a!eMEbY+uzYty6adoLa!yby&YTE5YZo5uqESU8e8ajY=ySAni@Y4YrohAZUPupo!unaZoWuweZY@EbYriqUBaSY7ewedi6Y4Ave7o%UrURYHi7opY%oTeMu!uQi=ono+A6yhy2eWa2UXoxaSaLUwEpE*U5o*iqi5a@iPAwiQabi!ubeDe3upYMy5enUMAWygo@EboZe7aXySo8obEzeqY*ytYDuQY*e7UWo%YLiro=U+YpaQy4imube4ApY+uMe&o3AVeZUgYnosohy!Etode6aho8U4o
>  
> user3"
>     - "ssh-rsa 
> rExaWAZu8U4u*uBy4yLYbEDi=aZeqeHotiPAMYRaQe4EdU8e%ABENo5Y2i=yrA8o&E@iqy+EgyRU!e5Y%o@aNE&y1UhELyda=U2oTU5e&a2ixeSYmYXAtinyMEzaHU6Y=Yju5uBoty2o2UJoTo6eRAWE2YNyjuRePE7ELoQy*yxY@E2UZU6EjU2uHYbEDiruvA!UhUqygeXu=AGUTuJi2agAme6EWosazuxa4UpowUdAdU%a8AgEZEJywytUwYMERa4y4Ano4utYSudaMyvU!iXAQE%oSuvipATyZu5oxEXu5AsurASU8Utu!ovUqabyDYviDY4oTU&uWU%ETE8AbY!E+yBYqUxArUTuSeju%AHE7uva7AHu
>  
> user3"
>
>
>
>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1d71689a-e9fd-4f3e-84a1-4a7e13124e45%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to