I am new to Ansible
( have basic working knowledge ). Trying to automate disk addition on linux machine from ansible playbook.
Below are the things trying out to achieve this.
- I tried to identify new disk which is attached on linux machine. From command line I am able to identify the new disk name but failing to find out with ansible.
Which module i need to write for this. Have tried with shell command for /sys/block
but its not working hence I left this condition.
- Now i decided that i will scan the disk manually and will provide that name in
ansible
to create partition automatically.
For this i wrote below code.
- name: list out currnet PV
shell: pvs --noheadings -o pv_name
register: pvs_list
- debug: var=pvs_list.stdout
- name: create partition on the given disk name
shell: /bin/echo -e "n\np\n1\n\n\nt\n8e\nw" | fdisk "{{ disk_name }}" ## Create the partition on a disk.
register: partitioning
Above code works fine but if i run this job again it does not fail and it recreate new partition in disk again.
I tried to apply when / failed_when condition but its not working.
If the already existing disk is been provided again the play should fail with proper message.
failed_when: "'{{ disk_name }}"' in pvs_list.stdout"
This condition also not working.
Also not able to identify new disk with Ansible.