Answer the question
In order to leave comments, you need to log in
How to tell Ansible to get permissions via sudo?
Hello. I understand with Ansible, I decided to start by creating a service user, which he will use to go to the servers. Because doing it manually is tedious and illogical, wrote the playbook:
---
- hosts: myservers
remote_user: myuser
become: yes
become_user: myuser
become_method: sudo
tasks:
- name: create ansible user
user:
name: ansible
shell: /bin/bash
home: /home/ansible
- name: copy ssh pubkey to home directory
authorized_key:
user: ansible
key: "{{ lookup('file', './ansible_pubkey') }}"
- name: adding ansible user to sudoers
lineinfile:
dest: /etc/sudoers
line: "ansible ALL=(ALL) NOPASSWD: ALL"
validate: 'visudo -cf %s'
ansible-playbook -i hosts add-ansible-user.yml -k
TASK [create ansible user] *****************************************************
fatal: [myserver]: FAILED! => {"changed": false, "cmd": "/sbin/useradd -d /home/ansible -s /bin/bash -m ansible", "failed": true, "msg": "[Errno 13] Отказано в доступе", "rc": 13}
Answer the question
In order to leave comments, you need to log in
Solved, helped on another resource. From off documentation:
become_user set to user with desired privileges, the user you 'become', NOT the user you login as. Does NOT imply become: yes, to allow it to be set at host level.become_user specifies the user whose rights you want to get through sudo, respectively, you had to specify root'a, not myuser.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question