Sometimes you might want to do things in localhost. My example is that I want to mount a share locally so that I can create directories for mount points and different permissions. I don’t want to spin up a new machine to do this simple task so I will run Ansible on the localhost which is my Azure DevOps Agent.

Ansible Playbook:

For host we are setting it to self and not gathering facts. I am mounting the share and creating dirs, for this example I will use 755 but I will be adding different permissions and users later.

Azure DevOps Agent Capabilities

Find the user that was configured to run the devops agent by going to your agents and checking its capabilities:

Linux SUDO

Since we need to mount and modify /etc/fstab we will need sudo to elevate our permissions and perform the edit. Make sure your Azure DevOps agent user is in the sudoers.

<username> ALL=NOPASSWD: ALL

Azure DevOps Task

I am choosing to run ansible via command since I am using parameters. Make sure you set the agent to the ones that have the account in sudoers

Success!