![]() Ansible will ask for root password, create a system admins group with access to sudo, create an user account based on your current user, copy your ~/.ssh/id_rsa.pub to your new account, and add it to the admins group.įrom now you can use Ansible through your user account using sudo. Run Ansible with: ansible-playbook -k -l host init.yml. Lineinfile: "dest=/etc/sudoers.d/admins state=present create=yes regexp='^%admins' line='%admins ALL=(ALL:ALL) NOPASSWD: SETENV: ALL' owner=root group=root mode=0440" name: INIT | Install sudoers file for admin accounts name: INIT | Install ssh public key from current accountĪuthorized_key: user=$ssh_user key="$FILE(~/.ssh/id_rsa.pub)" name: INIT | Make sure essential software is installedĪpt: pkg=$item state=latest install_recommends=no While still logged in to your Ansible control server as the ansible user, you simply run ssh-copy-id ansibletarget-server where target-server is the DNS name of the server you would like to push. User: name=$ssh_user state=present shell=/bin/bash groups=admins name: INIT | Create admin account from current user ![]() Group: name=admins system=yes state=present I created a key pair on my local machine (ubuntu) and copied it to my EC2 instances using ssh-copy-id. To grant access to the public key, copy it to all nodes in the cluster (including current node) using the ssh-copy-id. Make sure that you can ssh into the using password (accept host fingerprint, etc.). 2 I want to connect ansible to EC2 via ssh.After installation, default password for root account will be debian and you will be forced to change it upon first login. ![]() If you want to test it on a VM, you can run Debian installer with boot parameter url= - installer will download a preseed file with python and python-apt packages selected (among others). If I try to ssh throw ansible: ansible-playbook -i hosts playbook. When I try to ssh to that server everything works fine: ssh useripaddress User is not a root. ssh-copy-id -i /.ssh/idrsa.pub USERNAMEIP. I'm generated ssh key, and copy it to remote server. Host needs to have python and python-apt packages installed for this playbook to work out of the box. How to use password authentication when you ssh to a machine with ansible. Here's a method I use to provision new Debian hosts without known ssh keys.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |