how to reset root password by ansible [closed] - ansible

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
we have the servers where root passwd needs to be reset by ansible.
I ran the command below to get the hash passwd and input our correct root passwd:
python3 -c 'import crypt,getpass;pw=getpass.getpass();print(crypt.crypt(pw) if (pw==getpass.getpass("Confirm: ")) else exit())'
Password:
Confirm:
$6$c/98MRPOs7JQ.pbw$XI7Qyz80d5ZV2DcgMk8limxB9DoTNsTCIZVYtLRTkM3a5T6NnHOgxEoRq/te4jIJhm114HuTXLv0dMf5H
then, I added that generated root password in my playbook:
tasks:
- name: Change user password
user: name=root update_password=always password=$6$c/98MRPOs7JQ.pbw$XI7Qyz80d5ZV2DcgMk8limxB9DoTNsTCIZVYtLRTkM3a5T6NnHOgxEoRq/te4jIJhm114HuTXLv0dMf5H
ran that playbook without errors, then tried to login with that actual (not hash encrypted) root password on the server, but it does not work, what I am doing wrong and how it can be fixed ?

Your hash is probably not correct. Maybe an incompatible hashing-algorithm was used.
There are multiple ways to generate that hash:
The ansible-way:
ansible all -i localhost, -m debug -a "msg={{ 'mypassword' | password_hash('sha512', 'mysecretsalt') }}"
The mkpasswd:
mkpasswd --method=sha-512
Or with python:
python -c "from passlib.hash import sha512_crypt; import getpass; print(sha512_crypt.using(rounds=5000).hash(getpass.getpass()))"
You need to install passlib first.

Related

database login using shell scripting [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
This is the Database entry of my application in server.properties file.
umpdb.driverClassName=org.mariadb.jdbc.Driver
umpdb.url=jdbc:mysql://10.66.11.44:3306/MT_SMS_CHN?useUnicode=true&characterEncoding=UTF-8
umpdb.username=stackuser
umpdb.password=stackpass
I want to print mysql -uuser -ppasswrod -hhostname dbname using linux command.
It means, I need output as below
mysql -ustackuser -pstackpass -h10.66.11.44 MT_SMS_CHN
Please help me for this.
Using awk
awk -F'[:=/?]' '/url/{
h=$6" "$8 # get host and database
}
/username/{
u=$2 # get username
}
/password/{
# print username, password, host and database
printf("mysql -u%s -p%s -h%s\n",u,$2,h);
# we got what we want, exit
# if your file contains more than 1 db config
# just comment below exit keyword
exit
}
' server.conf
Test Results:
$ cat server.conf
umpdb.driverClassName=org.mariadb.jdbc.Driver
umpdb.url=jdbc:mysql://10.66.11.44:3306/MT_SMS_CHN?useUnicode=true&characterEncoding=UTF-8
umpdb.username=stackuser
umpdb.password=stackpass
$ awk -F'[:=/?]' '/url/{h=$6" "$8}/username/{u=$2}/password/{printf("mysql -u%s -p%s -h%s\n",u,$2,h); exit}' server.conf
mysql -ustackuser -pstackpass -h10.66.11.44 MT_SMS_CHN

ansible expect module respond to password prompt

I have read the documentation related expect module on here
I'm trying to add a CentOS7 to 2012 AD Domain controller, here is my playbook,
- name: Attempt to join the server to AS
expect:
command: realm join --user=admin#mydomain.local mydomain.local
responses:
(?i)Password for admin#mydomain.local: abc123
Ansible playbook fails, saying the password is incorrect, is this the correct way of using expect?
Have you try to incapsulate the password in quotes like so?
(?i)Password for admin#mydomain.local: "abc123"

How to verify multiple server's root password using bash script?

I've two text files one with list of server name's, another file with their root password (Unique password)
I have to check all server root password by logging to individual servers. but the issue is, by default ssh root login is disabled. Hence i have to login via my normal user(Test) and switch as root and try the root password which is mentioned in the text file.
is there any way i can get this automated ? highly appreciate if anyone can help me out.
Linux passwords are stored in /etc/shadow files.
They're just hashed plain-text, no magic.
Take a look at python's crypt.crypt() function.
# change 'root' password to 'secret' (demo only)
$ echo root:secret | chpasswd
Password for 'root' changed
# get 'root' hashed password
$ grep root /etc/shadow
root:$6$YvK0oNOm$k.zELztgUM2LajbVGsqtp5I3mGP3clC6vL7rNdVCNfg2FUtLOnfb94Bn6acfCp4cQpXxSAZ1Zt55K8rAgQ3nT0:16673:0:::::
# verify hashed password is correct
$ python -c 'import crypt; print crypt.crypt("secret", "$6$YvK0oNOm$") == "$6$YvK0oNOm$k.zELztgUM2LajbVGsqtp5I3mGP3clC6vL7rNdVCNfg2FUtLOnfb94Bn6acfCp4cQpXxSAZ1Zt55K8rAgQ3nT0"'
True
You can collect shadow files from all servers, and verify them locally.
WARNING: Shadow files are very sensitive.
This is a simple solution.
input.csv
192.168.1.1,secret,$6$YvK0oNOm$k.zELztgUM2LajbVGsqtp5I3mGP3clC6vL7rNdVCNfg2FUtLOnfb94Bn6acfCp4cQpXxSAZ1Zt55K8rAgQ3nT0
192.168.1.2,pAssWd,$6$AbcdeFgh$1234fsXXXXXXXXXXXsqtp5I3mGP3clC6vL7rNdVCNfg2FUtLOnfb94Bn6acfCp4cQpXxSAZ1Zt55K8rAgQ3nT0
192.168.1.3,123456,$6$efsjdsix$8787sdfsdsdfsd232sqtp5I3mGP3clC6vL7rNdVCNfg2FUtLOnfb94Bn6acfCp4cQpXxSAZ1Zt55K8rAgQ3nT0
check.py
import csv, crypt
for i, j, k in csv.reader(open('input.csv')):
if crypt.crypt(j, k) != k:
print i
result
$ python check.py
192.168.1.2
192.168.1.3

How to enumerate running ec2 instances and load them into a database using ruby? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm using aws-sdk gem, I can't figure how to list all the running ec2 instances and load them to a database.
I need an approach on how to do it.
require 'aws-sdk-v1'
ec2 = AWS::EC2.new(
access_key_id: 'YOUR_ACCESS_KEY_ID',
secret_access_key: 'YOUR_SECRET_ACCESS_KEY',
region: 'YOUR_EC2_REGION'
)
ec2.instances
http://docs.amazonwebservices.com/AWSRubySDK/latest/frames.html
The answer above will return all instances, not just running instances. You can use a filter to get only running instances:
ec2 = AWS::EC2.new
ec2.instances.filter('instance-state-name', 'running')
Install the AWS ClI and run the following to get a list of running instance ids:
aws ec2 describe-instances --filter "Name=instance-state-name,Values=running" \
| grep InstanceId | awk '{print $2}' | sed 's/^\"//g' | sed 's/\",$//g'

How to edit hosts file via CMD? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Hello I'd like to block some websites directly from the command prompt.
echo like this:
0.0.0.0 websitename.com
How can I do this? (OS: Windows 7)
echo 0.0.0.0 websitename.com >> %WINDIR%\System32\Drivers\Etc\Hosts
the >> appends the output of echo to the file.
Note that there are two reasons this might not work like you want it to. You may be aware of these, but I mention them just in case.
First, it won't affect a web browser, for example, that already has the current, "real" IP address resolved. So, it won't always take effect right away.
Second, it requires you to add an entry for every host name on a domain; just adding websitename.com will not block www.websitename.com, for example.
Use Hosts Commander. It's simple and powerful. You can download it here.
Examples of using
hosts add another.dev 192.168.1.1 # Remote host
hosts add test.local # 127.0.0.1 used by default
hosts set myhost.dev # new comment
hosts rem *.local
hosts enable local*
hosts disable localhost
...and many others...
Help
Usage:
hosts - run hosts command interpreter
hosts <command> <params> - execute hosts command
Commands:
add <host> <aliases> <addr> # <comment> - add new host
set <host|mask> <addr> # <comment> - set ip and comment for host
rem <host|mask> - remove host
on <host|mask> - enable host
off <host|mask> - disable host
view [all] <mask> - display enabled and visible, or all hosts
hide <host|mask> - hide host from 'hosts view'
show <host|mask> - show host in 'hosts view'
print - display raw hosts file
format - format host rows
clean - format and remove all comments
rollback - rollback last operation
backup - backup hosts file
restore - restore hosts file from backup
recreate - empty hosts file
open - open hosts file in notepad

Resources