I have a group of .keys files in the / files folder. I want to create users on remote hosts that match these key files.
Say I have alice.keys, bob.keys and john.keys in / files. I want the script to create alice, bob and john users if they do not exist, and update / add SSH keys from the corresponding .keys file for each user.
I know that I can use the module loop
to scroll through files, but I donβt know how to create a list that contains only file names, so I can use it later.
My role structure is as follows:
sshrole
βββ defaults
β βββ main.yml
βββ files
β βββ alice.keys
β βββ bob.keys
β βββ john.keys
βββ handlers
β βββ main.yml
βββ README.md
βββ tasks
β βββ main.yml
β βββ setup.yml
β βββ update.yml
β βββ useradd.yml
β βββ userdel.yml
βββ templates
β βββ ssh_config.j2
βββ vars
βββ main.yml
In short, I want to have a variable ssh_users
containing values {'alice', 'bob', 'john'}
.
UPDATE:
, ββ, :
- name: Extract user-names.
shell: echo {{item}} | sed 's/.*\/\(.*\)\.keys/\1/'
register: sed_commands
with_fileglob: ../files/*.keys
{{sed_commands.results}} .