o switch the user in Ansible before executing a specific command like ln -s, you use the become directive. Since you want to switch specifically to the cometgran user, you need to combine become: true with become_user: cometgran.
Here is the most common way to implement this in your playbook:
- The Task-Level Switch (Recommended) This is the safest method because it only elevates privileges for that specific symlink command, keeping the rest of the playbook running under your default connection user.
YAML
- name: Create symlink as cometgran user ansible.builtin.file: src: "/opt/CPLS/{{ app_version }}" dest: "/opt/CPLS/current" state: link become: true become_user: cometgran
Top comments (0)