Skip to main content

Preparing Ansible Managed Nodes - shell script

#!/bin/bash

rootpwd='Passw0rd!'
remuser=devops
devpass=redhat123

ansible all -e "ansible_password=$rootpwd" -u root -m user -a "name=$remuser state=present"

ansible all -e "ansible_password=$rootpwd" -u root -m shell -a "echo $devpass | passwd --stdin $remuser"

ansible all -e "ansible_password=$rootpwd" -u root -m authorized_key -a \
   "user=$remuser state=present key='{{ lookup('~/.ssh/id_ecdsa.pub') }}'"

ansible all -e "ansible_password=$rootpwd" -u root -m copy -a \
   "dest=/etc/sudoers.d/training content='devops ALL=(ALL) NOPASSWD: ALL' mode=0600 owner=root group=root"

Alternative solution: Preparing Ansible managed nodes using playbook

 

--stdin option in passwd utility is only available in Redhat's version.