When I run this on the command line it works fine:
echo -e \"n\\np\\n1\\n\\n\\nw\" | sudo fdisk /dev/sdb
But in Ansible it does not want to ru
By default, Ansible executes /bin/sh shell.
For example, if /bin/sh is linked to dash, it's built echo is different to the one in bash or GNU echo; so you end up with -e characters fed into fdisk.
Try:
- name: partition new disk
shell: echo -e "n\np\n1\n\n\nw" | sudo fdisk /dev/sdb
args:
executable: /bin/bash
Or:
- name: partition new disk
shell: /bin/echo -e "n\np\n1\n\n\nw" | sudo fdisk /dev/sdb