Thanks for that. Guess I need to learn more about the stdout options
On Sunday, April 16, 2023 at 2:29:07 PM UTC-4 Kai Stian Olstad wrote:
> 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/145d309a-dfe2-4756-b46f-53fb6bd97a81n%40googlegroups.com.