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