For this problem, you need to make some changes to your play-book which will help you can do ssh into the server as deployed. Changes are given below
- name: Make sure we have a 'wheel' group
group:
name: wheel
state: present
- name: Allow 'wheel' group to have passwordless sudo
lineinfile:
dest: /etc/sudoers
state: present
regexp: '^%wheel'
line: '%wheel ALL=(ALL) NOPASSWD: ALL'
validate: 'visudo -cf %s'
- name: Add sudoers users to wheel group
user: name=deployer groups=wheel append=yes state=present createhome=yes
- name: Set up authorized keys for the deployer user
authorized_key: user=deployer key="{{item}}"
with_file:
- /home/railsdev/.ssh/id_rsa.pub
Here in the above code, there is a line that helps you to access
%wheel ALL=(ALL) NOPASSWD: ALL
To /etc/sudoders. After executing this play in a subsequent time then you will be able to ssh into the server as a deployer.
You can read more about Ansible, a DevOps configuration management tool, and you can also refer to Ansible Tutorial for better understanding.