0

Trying to get the ansible expect module going for a list style response rather than a text response. I've read the ansible documentation for this module and its not so clear how to achieve this, I've also looked around google for examples similar to what I'm trying to achieve without any success.

Perhaps I'm trying to use the wrong module for the wrong thing?

I'm basically trying to run 'npx @vue/cli create frontend' using ansible, but be able to select 'merge' and 'Default ([Vue 2] babel, eslint)' when they show up as options.

Any suggestions on getting this going would be much appreciated. Here is an example of the list style response expected in the terminal. example of list response

And here is a code snippet of what I've got so far:

 - name: create node package in front-end directory
   expect:
     command:
       cmd: 'npx @vue/cli create frontend'
       args:
         chdir:  '{{ app_root }}'
         virtualenv: '{{ virtualenv_dir }}'
     responses:
       already exists. Pick an action: Merge
       Please pick a preset: Default ([Vue 2] babel, eslint)
   become_user: '{{ username }}' 
ant
  • 1
  • 1
  • Hi ant, welcome to SO. The `expect` utility was designed for an era before fancy ANSI terminal sequences become the norm for command-line apps. Your program's screenshot is waiting for cursor movement, not typing, which is why it is not behaving sanely. I would suggest looking at the output of `npx @vue/cli create frontend --help` or similar to see if there is a way you can specify its arguments without interaction. Good luck! – mdaniel Feb 18 '21 at 05:13

1 Answers1

0

Thanks to the user mdaniel for providing a workaround to my issue. Working code snippet is as follows:

- name: Vue | create node package in frontend directory
  become_user: '{{ username }}' 
  command: 'npx @vue/cli create {{ frontend_name }} --merge --default'
  args:
    chdir:  '{{ app_root }}'
ant
  • 1
  • 1