Hi,

I'm trying to understand when ansible uses sudo in a scenario where a 
playbook with become:yes is running with a local connection.

I have a playbook where I need to change the default execution PATH in 
sudoers for a following step to succeed. In order to run the playbook 
remotely, I need the tasks to run under "become:yes"

Something like this:

- hosts: all
  become: yes
  tasks:
    - name: Add npm executable to sudo secure_path
      lineinfile:
        dest: /etc/sudoers
        regexp: '^(Defaults    secure_path = 
/sbin:/bin:/usr/sbin:/usr/bin)$'
        line: '\1:/usr/local/lib/npm/bin'
        backrefs: yes
        state: present
    - name: Add service to run PM2
      shell: /usr/local/lib/npm/bin/pm2 startup systemd --user nodejs --hp 
/home/nodejs
      args:
        creates: /etc/systemd/system/pm2.service

Running each of the above tasks in separate sessions sets things up 
properly. But when I run this locally in the same play, the change to the 
sudoers file has no effect on the "pm2 startup" task.

When does ansible call sudo? Just at the start of the block? Is there any 
way to force ansible to leave a sudo session and to start a new one?

Thanks,
David

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f6f5deff-2fd0-47f7-8c7a-19d309d5131f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to