Can Ansible interact with an application?

114 views
Skip to first unread message

richard kappler

unread,
Apr 13, 2016, 9:16:59 AM4/13/16
to Ansible Project
I am writing a playbook to set up new VM's remotely, and two of the tasks require interaction with a utility and an app, and I'm presuming this could be done in Ansible, but have no idea how, so I'm looking for a pointer to the appropriate tutorial, or confirmation that Ansible can't do it. 

The first task is setting up the partitions, so I would need to start either fdisk or parted (easy) but then I need to input commands to create the partitions, wait for a new prompt, etc etc, then quit the utility. Here's how I would do it manually ($ = command line prompt, > = utility prompt):

$fdisk /dev/sda
>c
>u
>n
>p
>[Enter] #use default for beginning of new partition
>+15G  # make the partition 15GB in size
>n
>p
>[Enter] # default start of partition
>[Enter] # partition runs to end of disk
>w

The second task requires installing and setting up a MongoDB instance. I've got the installation bit ready and tested, but again have no idea how to set it up using Ansible. Specifically, I need to start the Mongo console (easy), but once the console is started, I need to give it a command that loads a .js which sets up the database. More specifically, once the console is started, it gives me a prompt (>) and waits for my input. I want ansible to then input 

>load("path/to/create-my-database.js")
>quit()

Can someone point me to pertinent tutorials?

regards, Richard

Edgars

unread,
Apr 13, 2016, 9:31:52 AM4/13/16
to Ansible Project
You can use parted in non-interactive mode, something like this:

command: parted -s /dev/{{ item.key }} unit s mklabel msdos mkpart primary 16384 100% set 1 lvm on

Or, there is expect module, but I don't recommend it in this case.

Edgars

richard kappler

unread,
Apr 13, 2016, 9:36:35 AM4/13/16
to Ansible Project
Brilliant! Thanks Edgars, I wasn't aware of non-interactive mode.
Reply all
Reply to author
Forward
0 new messages