On 14.05.2018 19:02, ZillaYT wrote:
> Per
https://groups.google.com/forum/#!topic/ansible-project/AXEPsAqxmNE
> I'm
> using the expect module, and have it working when the prompt is single
> line. How do I make it work when the prompt is multi-line? I'm not
> talking
> about multi-prompts.
>
> Let me explain.
>
> ansible v2.4.0.0
>
> I'm trying to automate JKS (Java Keystore) and CSR file generation via
> the
> keytool command (the java_cert module doesn't do this, IIUC).The
> command,
> and the first 3 prompts are the following. *Note that the third prompt
> is
> multi-lined.*
>
> $ keytool -genkey -alias tomcat -keyalg RSA -sigalg SHA1withRSA
> -keysize
> 2048 -keystore keystore.jks
> Enter keystore password:
> Re-enter new password:
> What is your first and last name?
> [Unknown]:
>
> I have
>
> ---
> - hosts: localhost
> connection: local
>
> tasks:
> - name: Test expect
> expect:
> echo: yes
> command: keytool -genkey -alias tomcat -keyalg RSA -sigalg
> SHA1withRSA -keysize 2048 -keystore keystore.jks
> responses:
> "Enter keystore password: " : "changeit"
> "Re-enter new password: " : "changeit"
> "What is your first and last name?\n [Unknown]: " :
> "
myserver.domain.com"
Expect is just looking a a stream of bytes, when it sees a string it
will "type" the response.
So in this case you only need to check for the string [Unknown]:
Since [] is special character in regex you need to escape them
"\[Unknown\]: ": "
myserver.domain.com"
You could also leave out the quotes, the colon and the space, this will
also work
\[Unknown\]:
myserver.domain.com
--
Kai Stian Olstad