On 12.04.2023 11:52, Kathy L wrote:
That is pretty cool. Mgmt is not thrilled with using a filter and want me to see if I can do it another way. I'm trying using the expect module, but
not getting the response I thought:

- name: Use expect
  expect:
    command: /usr/bin/grub-mkpasswd-pbkdf2
   responses:
        (?i)Enter password: "{{ random_plaintext_password }}"
        (?i)Reenter password: {{ random_plaintext_password }}"
  register: grub_hash
  delegate_to: 127.0.0.1

- name: Print grub_hash
  debug:
    msg: "Grub hash is {{ grub_hash.stdout }}"

However this prints the entire "exchange":

New grub hash is Enter password:
Reenter password:
PDKDF2 hash of your password is.....

Why is the entire exchange printed out?  I expected that the last line
above would be printed which I could then use cut on to print only the
password.

The .stdout contains everything that is printed to stdout, hence the name.
You have .stdout_lines where each lines is an element in the list,
so grub_hash.stdout_lines[-1] gives you the last line.

So what you are looking for is this

  {{ grub_hash.stdout_lines[-1].split()[-1] }}


--
Kai Stian Olstad

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6ec051cf3437b32a33ea46ba84c6ed9c%40olstad.com.

Reply via email to