Script runs but ansible fails?

This is a continuation of an earlier thread “Can Ansible interact with an Application.”

If Edgars is reading, I went a little different route. Parted won’t quite work as I’m adding two partitions to /dev/sda which already has boot, swap and root on it and is mounted. I did some research, and fdisk will do the job when run from a script, so I create a script as follows:

`

#!/bin/bash

echo "u
c
n
p
3

+15G
n
p

w"|fdisk /dev/sda

`

which creates 2 new partitions, /dev/sda3 from the end of /dev/sda2 at 15GB size, then creates /dev/sda4 from the end of /dev/sda3 to the end of the drive, and called it Apart.sh

My playbook copies it to /home in the target, makes it executable, then runs it.

In testing the script works, it creates the partitions as I expected, when I’ve tested it locally by itself (no Ansible). When Ansible runs it though, it crashes:

fatal: [partVSS] : FAILED! => {“changed”: true, “cmd”: [“/home/Apart.sh”], “delta”: “0:00:00.034351”, “end”: “2016-04-13 06:29:35.548649”, “failed”: true, “rc”: 1, “start”: “2016-04-13 06:29:35.514298”,

then it gives me the stderr and stdout outputs.

But it creates the partitions. The script works, even when Ansible runs it, but Ansible fails, crashes.

Any guidance here?

regards, Richard

Ansible is treated this as a failure because your command is returning a non-zero return code (“rc”: 1). Try running the command manually and then running ‘echo $?’ immediately after it and see if it also give a non-zero return code.

Assuming it’s normal that fdisk/your script returns non-zero, you can prevent Ansible from treating that as a failure with failed_when