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
- Ansible module
expectbut it timeout because it expecting the question which I've tried to write it in multiple ways and it doesn't reads the question. - Ansible module
partedbut 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 theignore_unreachable: falsebut it seems this is only useful when connecting to a host. - Ansible module
shellto execute the command(echo y; echo;) | /usr/sbin/parted /dev/vdc resizepart 1 4.0GBbut it didn't worked. I also tried(resizepart 1 4.0GB; echo y; echo;) | /usr/sbin/parted /dev/vdcand again it gets stuck with the question. fdiskdoes not have resize and it requires to delete a partition and recreate it, neither doessgdiskhave resize.- I tried
/usr/sbin/parted -s /dev/vdc resizepart 1 4.0GBwith the-soption so that it disables script prompts but it just ignores the answer and it exits the command.
Questions
- Is there's anyway to ignore the warnings in Ansible in order to answer it?
- How can I shrink a partition using Ansible without having to recreate it? Why do extra work when resizepart exists?
- Could I auto accept the question is parted?