

User: The username on the remote host whose authorized_keys file will be modified. It adds or removes SSH authorized keys for particular user accounts. Groups: A list of groups that the user will be added to.Īppend: This is used with the groups key and ensures that the group list is appended to.Ī_key: Ansible authorized_key module.
#Ssh copy id ansible password
Update_password: It will only set the password for newly created users. Passing user password to get sha512 password hash. State: Whether the account should exist or not. Name: Name of the user to create, remove or modify. It manage user accounts and user attributes.

Evvery task should have a name, which will show you in the output while running the playbook and also its easy for us to identify it.Ī: Ansible user module. Vars: definevariables- In our case, username and userpass. Gather_facts: We are not using any gather facts in this playbook so disabling it. Hosts: lists of hosts or host group against which we want to run the task.īecome: Instructs the remote host to execute the playbook as admin. Replace your new user with their password in variable username and userpass of playbook. We have used 2 modules for this user and authorized. The play has 2 tasks: Create user and Deploy SSH Public Key. In this Playbook it contains a single play. We should be more cautions with the spaces while writing ansible playbook. Srv-02 | SUCCESS => Īll servers are reachable through ansible admin user. To run the playbook we are using an ansible admin user “ansible_admin”. I have also defined common variables for both groups. To give admin privileges to a normal user, in Ubuntu users should be in sudo group and in CentOS users should be in wheel group, so I’ve defined variable super_group for this. Here I have defined 2 groups CentOS and Ubuntu for our all hosts. This is an inventory file for our playbook. The key fingerprint is : SHA256:+Z/N055jsnrr2s/k7zg3IWA6SaURTmETeWFqC803vhM The key's randomart image is : +-+ | =+o. Your public key has been saved in /home/newuser/.ssh/id_rsa.pub. Enter passphrase (empty for no passphrase) : Enter same passphrase again : Your identification has been saved in /home/newuser/.ssh/id_rsa. Enter file in which to save the key (/home/newuser/.ssh/id_rsa) : Created directory '/home/newuser/.ssh'. $ ssh-keygen Generating public/private rsa key pair.
