Hi all,

I have created a directory 'users' alongside my inventory. It has a directory 'user_vars', intended to be used like host_vars, but for users, obviously.

In there, I have files like this:

=====================
---
name: richard
gecos: 'Richard Hector,,,'
shell: '/bin/bash'
ssh_keys:
  - richard@foo
  - richard@bar
=====================

Then in host_vars/all, I have this kind of thing:

=====================
---
users:
  - richard
admins:
  - richard
ansible_users:
  - richard
=====================

I also have users/public_keys, which has a file for each of 'richard@foo' etc, containing one key.

Where I'm stuck is reading in the user_vars file(s).

I want to get rid of what I used to have:

=====================
- name: users
  user:
    name: '{{ item.name }}'
    comment: '{{ item.gecos }}'
    shell: '{{ item.shell }}'
    createhome: yes
    state: present
    groups: '{{ item.groups }}'
    append: yes
  with_items:
- { name: 'richard', gecos: 'Richard Hector,,,', shell: '/bin/bash', groups: [ 'sudo', 'adm' ] }
  tags:
    - users
======================

since I want to separate data from the rest of my config.

So I'd like to either read all the user_vars files into a single dictionary before I run that loop, or read each file in its own iteration of the loop - or something better if that's the answer.

I thought about using set_fact in a loop, but that would give me separate facts/variables for each user, making it harder(?) to index them (but maybe by text templating the variable name?)

I also thought about doing a lookup in every line of the user loop above, but that seems wasteful, and I'm not sure how I'd do it anyway.

Any suggestions?

Thanks,
Richard

--
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/bb093b37-e90b-115b-593c-d535b5945f7b%40walnut.gen.nz.

Reply via email to