The destination directory (/etc) is not writable by the current user on ansible
you should configure admin
as a remote_user
, not become_user
. The become_user
option sets to which user you would su
to execute certain task. In other words, your playbook should look like:
---
- hosts: somehosts
remote_user: admin
roles:
....
#tasks file
---
# tasks file for test
- name: Change dns
become: yes
replace:
dest: /etc/resolv.conf
regexp: '192.168.1.24'
replace: '8.8.8.8'
That way the admin user will be used to establish your ssh session, but for the Change dns
task will be used sudo
.
Also, if admin
requires password for sudo, you will have to run your playbook like this:
ansible-playbook -i mn test.yml -K
The -K
switch will prompt you for the sudo password for admin
.