How to specify the user home directory dynamatically with /home/{{ 'echo{$USER}' }}/sub_dir for copying files with Ansible copy module ?

Hi,

I would like to use git for managing Ansible playbooks for version control on an admin server in GCP. So the idea is this:

each user in the admin group to run the playbooks pulled from the github ino their repo from each user’s home. for exampel:
for user1,
run ansible playbooks from: adminserver:/home/user1/user1_git_repo/playbooks

for user1,
run ansible playbooks from: adminserver:/home/user2/user2_git_repo/playbooks

etc.

I have this Ansible playbook but it doesn’t work:

Frank,

Something like this should work:

  • name: Copy the sudoers file from ~/managed_files/sudo_ii/sudoers to /etc on the remote VMs
    copy:
    src: "{{ lookup(‘env’,HOME) }}/managed_files/sudo_ii/sudoers
    dest: /etc
    owner: root
    group: root
    mode: ‘0440’

See https://docs.ansible.com/ansible/latest/plugins/lookup/env.html

Also, use the ‘validate’ parameter when you’re deploying sudoers files.
Without this, mistakes can cause you to completely lose access.

Hi Michael,

Thanks for the tip. Yes, it works.

Frank

Dick,

Thanks for the suggestion.

We use visudo for editing the sudoers file in the first place. So if any mistakes made we could catch up in the first place.

Your suggestion is the good one, and I like it.

Frank