# Can Ansible interact with an application?

**URL:** <https://forum.ansible.com/t/can-ansible-interact-with-an-application/21150>\
**Category:** Ansible Project\
**Created:** [April 13, 2016, 1:16pm UTC](https://forum.ansible.com/t/can-ansible-interact-with-an-application/21150 "2016-04-13T13:16:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![richard\_kappler](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@richard\_kappler](https://forum.ansible.com/u/richard_kappler)\
**Post date:** [April 13, 2016, 1:16pm UTC](https://forum.ansible.com/t/can-ansible-interact-with-an-application/21150/1 "2016-04-13T13:16:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Edgars](https://avatars.discourse-cdn.com/v4/letter/e/f17d59/32.png) [@Edgars](https://forum.ansible.com/u/Edgars)\
**Post date:** [April 13, 2016, 1:31pm UTC](https://forum.ansible.com/t/can-ansible-interact-with-an-application/21150/2 "2016-04-13T13:31:51Z")

</div>

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

trešdiena, 2016. gada 13. aprīlis 15:16:59 UTC+2, richard kappler rakstīja:

---

<div class="post-metadata">

**Author:** ![richard\_kappler](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@richard\_kappler](https://forum.ansible.com/u/richard_kappler)\
**Post date:** [April 13, 2016, 1:36pm UTC](https://forum.ansible.com/t/can-ansible-interact-with-an-application/21150/3 "2016-04-13T13:36:35Z")

</div>

Brilliant! Thanks Edgars, I wasn’t aware of non-interactive mode.
