1

When ever I run my ansible playbook I always get,

TASK [set password] ****************************************************************
changed: [10.1.38.15]

As an entry in the log. I don't want that to show, as the password was already set. Is there a way for ansible to track to easily track this?

My play is

- name: set password                                                            
  run_once: true                                                                
  user:                                                                         
    name: root                                                                  
    password: "{{ 'bleh' | password_hash('sha512') }}"                      
    expires: -1

I even tried run_once which I saw others mention.

1 Answer 1

2

This is indeed what should happen. However, you do not pass the same encrypted password every time: password_hash can take a salt as a second parameter. If absent, one is generated randomly. (Salt is used to protect against pre-computed dictionary attacks, so the hash value for bleh will be different every time)

Compare:

ansible all -i localhost, -m debug -a "msg={{ 'mypassword' | password_hash('sha256') }}"

run several times, with result changing, with

ansible all -i localhost, -m debug -a "msg={{ 'mypassword' | password_hash('sha512', 'mysecretsalt') }}"

where the result stays the same because you fix the salt.

2
  • that works, thanks Commented Jan 6, 2020 at 16:23
  • That took a minute to sink in to my brain. While you are technically not changing the password, you ARE making a change every time (without the predefined salt), because ansible is writing a new hashed value (of the same password) into the shadow file. Wow. /insert head explode emoji
    – 0xSheepdog
    Commented Jan 9, 2020 at 1:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .