Somehow I found this annoyingly cumbersome...
Two options which came to my mind:
1. Pass pwd to the chpasswd
which works as:
CHPASSWD(8)
NAME
chpasswd - update passwords in batch mode
SYNOPSIS
chpasswd [options]
DESCRIPTION
The chpasswd command reads a list of user name and password pairs from standard input and uses this information to update a group
of existing users. Each line is of the format:
user_name:password
So, your chef recipe could look like:
password = 'my-secret-password'
bash 'analytics_password' do
code <<-EOH
sudo sh -c 'echo "adminblah:#{password}" | chpasswd'
EOH
end
2. Use user
resource
hash = `openssl passwd -1 -salt NCC #{password}`
hash = hash.gsub(/\n/, '')
user 'a user' do
username 'adminblah'
password hash.to_s
end
I hope that at least one of this methods will work :)
Best regards,
Jarek