Hi, I have been going at this all day and I've hit a bit of a dead end
within my knowledge of ansible and jinja2. And i've exhausted all google
searches.
Im trying to generate a config file for users this file needs to have a
unique password inserted into it per user.
# Vars
users:
- user1
- user2
- ...... etc......
Currently I'm generating this password like so.
# check for the passfiles
- name: Check for pass files
stat:
path: "/data/{{ item }}.pass"
register: passwords
become: true
with_items: "{{ users }}"
delegate_to: localhost
# Sets the file name to username.pass
- name: Generate Password
shell: "openssl rand -hex 21 | tee {{ item.item }}.pass "
become: true
when: "item.stat.exists == false"
delegate_to: localhost
with_items:
- "{{ passwords.results }}"
- name: Register passwords
shell: "cat /data/{{ item }}.pass"
delegate_to: localhost
register: user_passwords
with_items: "{{ users }}"
Now I could just use replace module / sed to insert the password into each
config file with a loop/with_items as the config file has a unique key.
but I've been trying to get this to work in Jinja with no luck so far.
{% if inventory_hostname in groups['storage'] %}
username = {{ users }}
password = {{ hostvars[groups['storage'][0]].user_passwords.stdout }}
{% endif %}
i know i can use a for loop in jinja and generate one big file that has all
the passwords in it but I need to have a Individual config file for each
user.
is using the ansible replace module / sed the way to go or can this be
achieved via jinja templating.
what i want to end up with is
file=joe.pass
username = joe
password = 2de4bb6f8d260200f46be938039c647676564781a381a1fe
file=bob.pass
username = bob
password = 28e451b174dc624ffd743cc3a52a6832ed3b7c1f9dfe8f6d
regards kd
--
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/631f1941-06c9-4e02-af71-a09e33cd5ad3n%40googlegroups.com.