How to auto confirm question with parted tool using Ansible in Linux

37 Views Asked by At

I'm trying to run /usr/sbin/parted /dev/vdc resizepart 1 4.0GB using Ansible playbooks, but this command asks the question "Warning: Shrinking can cause problems...." to which I want to answer y automatically. The resize will be done to a newly created volume that has a partition (/dev/vdc1), meaning that the is no data that will be lost. I can run the mentioned above in the shell and it works perfectly, whether is extending the space or shrinking it.

Things I've tried

  1. Ansible module expect but it timeout because it expecting the question which I've tried to write it in multiple ways and it doesn't reads the question.
  2. Ansible module parted but it gets stuck in the same question. This happens because when Ansible sees any word like Warning or Error it fails immediately. For this case I tried to ignore warnings by using the ignore_unreachable: false but it seems this is only useful when connecting to a host.
  3. Ansible module shell to execute the command (echo y; echo;) | /usr/sbin/parted /dev/vdc resizepart 1 4.0GB but it didn't worked. I also tried (resizepart 1 4.0GB; echo y; echo;) | /usr/sbin/parted /dev/vdc and again it gets stuck with the question.
  4. fdisk does not have resize and it requires to delete a partition and recreate it, neither does sgdisk have resize.
  5. I tried /usr/sbin/parted -s /dev/vdc resizepart 1 4.0GB with the -s option so that it disables script prompts but it just ignores the answer and it exits the command.

Questions

  1. Is there's anyway to ignore the warnings in Ansible in order to answer it?
  2. How can I shrink a partition using Ansible without having to recreate it? Why do extra work when resizepart exists?
  3. Could I auto accept the question is parted?
0

There are 0 best solutions below