# Automate a command which requires random keystrokes

**URL:** <https://forum.ansible.com/t/automate-a-command-which-requires-random-keystrokes/28462>\
**Category:** Ansible Project\
**Created:** [August 29, 2018, 10:52pm UTC](https://forum.ansible.com/t/automate-a-command-which-requires-random-keystrokes/28462 "2018-08-29T22:52:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bharath\_Kumar2](https://avatars.discourse-cdn.com/v4/letter/b/91b2a8/32.png) [@Bharath\_Kumar2](https://forum.ansible.com/u/Bharath_Kumar2)\
**Post date:** [August 29, 2018, 10:52pm UTC](https://forum.ansible.com/t/automate-a-command-which-requires-random-keystrokes/28462/1 "2018-08-29T22:52:47Z")

</div>

Hello All,

I have a command that has to be automated/written into playbook that requires 15-20 random keystrokes.

The scenario is; I am using certutil to generate a key.

The certutil command when run manually on the shell, asks for few keystrokes to fill in a empty space between two vertical bar with keystrokes on the cmd. Some thing like |\*\*\*\*\*\*\*\*\*|.

How do i automate this using Ansible.

**Play**

`

- name: Generating CSR  
command: certutil -R -k rsa -g 2048 -n cert -s “CN={{ ref\_number }}, OU=MyOU, O=MyO, L=MyL, ST=MyST, C=MyC” -d {{ dir\_path }} -f {{ pass\_file }} -a -o {{ ansible\_fqdn }}.csr  
`

**Error**

`  
stderr: |2-

A random seed must be generated that will be used in the  
creation of your key. One of the easiest ways to create a  
random seed is to use the timing of keystrokes on a keyboard.

To begin, type keys on the keyboard until this progress meter  
is full. DO NOT USE THE AUTOREPEAT FUNCTION ON YOUR KEYBOARD!

Continue typing until the progress meter is full:

> > >

Finished. Press enter to continue:  
certutil: unable to generate key(s)  
: PR\_END\_OF\_FILE\_ERROR: Encountered end of file  
stderr\_lines:

- ‘’
- A random seed must be generated that will be used in the
- creation of your key. One of the easiest ways to create a
- random seed is to use the timing of keystrokes on a keyboard.
- ‘’
- To begin, type keys on the keyboard until this progress meter
- is full. DO NOT USE THE AUTOREPEAT FUNCTION ON YOUR KEYBOARD!
- ‘’
- ‘’
- ‘Continue typing until the progress meter is full:’
- ‘’
- ‘’
- ‘| |’
- ‘|’
- ‘’
- 'Finished. Press enter to continue: ’
- ‘certutil: unable to generate key(s)’
- ‘: PR\_END\_OF\_FILE\_ERROR: Encountered end of file’  
`

---

<div class="post-metadata">

**Author:** ![flowerysong1](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@flowerysong1](https://forum.ansible.com/u/flowerysong1)\
**Post date:** [August 29, 2018, 11:36pm UTC](https://forum.ansible.com/t/automate-a-command-which-requires-random-keystrokes/28462/2 "2018-08-29T23:36:12Z")

</div>

Use the -z flag to supply certutil with a noise file. Unfortunately certutil will attempt to read as much data as possible from this file so you can’t point it directly at /dev/urandom, but if you don’t have anything suitably random to point it at you can easily create a noise file in a separate step:

`

- name: Create noise file  
command: dd if=/dev/urandom of=/var/cache/noise count=1

- name: Generate CSR  
command: certutil -R -k rsa -g 2048 -n cert -s “CN={{ ref\_number }}, OU=MyOU, O=MyO, L=MyL, ST=MyST, C=MyC” -d {{ dir\_path }} -f {{ pass\_file }} -z /var/cache/noise -a -o {{ ansible\_fqdn }}.csr

`
