# ansible playbook not printing the error message when disk is not defined

**URL:** <https://forum.ansible.com/t/ansible-playbook-not-printing-the-error-message-when-disk-is-not-defined/33112>\
**Category:** Ansible Project\
**Created:** [June 7, 2020, 1:59pm UTC](https://forum.ansible.com/t/ansible-playbook-not-printing-the-error-message-when-disk-is-not-defined/33112 "2020-06-07T13:59:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajesh](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@Rajesh](https://forum.ansible.com/u/Rajesh)\
**Post date:** [June 7, 2020, 1:59pm UTC](https://forum.ansible.com/t/ansible-playbook-not-printing-the-error-message-when-disk-is-not-defined/33112/1 "2020-06-07T13:59:30Z")

</div>

Hi all,

The below playbook is not printing an error message when the disk is not defined on a host. Could you please advise if I have made an mistake in the playbook. Thanks

- name: Create a partition  
hosts: all  
become: true  
become\_user: root  
tasks:

- name: Gather disk info  
parted:  
device: /dev/sdb  
unit: MB  
register: device\_info

- name: Print disk info  
debug:  
var: device\_info

- name: Create partition  
parted:  
device: /dev/sdb  
number: 1  
part\_start: 1MB  
part\_end: 1200MB  
unit: MB  
state: present  
when: device\_info.disk.size \> 1200

- name: Print enough size is not available  
debug:  
msg: “Enough size is not available”  
when: device\_info.disk.size \< 1200

- name: Create 800MB partition  
parted:  
device: /dev/sdb  
number: 1  
part\_start: 1MB  
part\_end: 800MB  
unit: MB  
state: present  
when: device\_info.disk.size \< 1200

- name: Create file system  
filesystem:  
device: /dev/sdb1  
fstype: ext4  
force: yes

- name: Create /exam directory  
file:  
path: /exam  
state: directory  
owner: root  
group: root  
mode: ‘0755’

- name: mount File system  
mount:  
path: /exam  
src: /dev/sdb1  
fstype: ext4  
state: mounted

- name: No extra hard disk  
debug:  
msg: “No extra hard disk available”  
when: ansible\_devices.sdb is undefined

$ ansible-playbook partition.yml

PLAY [Create a partition] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[ansible2.example.com](http://ansible2.example.com)]  
ok: [[ansible4.example.com](http://ansible4.example.com)]  
ok: [[ansible3.example.com](http://ansible3.example.com)]

TASK [Gather disk info] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [[ansible4.example.com](http://ansible4.example.com)]: FAILED! =\> {“changed”: false, “err”: “Error: Could not stat device /dev/sdb - No such file or directory.\n”, “msg”: “Error while getting device information with parted script: ‘/sbin/parted -s -m /dev/sdb – unit ‘MB’ print’”, “out”: “”, “rc”: 1}  
ok: [[ansible3.example.com](http://ansible3.example.com)]  
ok: [[ansible2.example.com](http://ansible2.example.com)]

TASK [Print disk info] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[ansible2.example.com](http://ansible2.example.com)] =\> {  
“device\_info”: {  
“changed”: false,  
“disk”: {  
“dev”: “/dev/sdb”,  
“logical\_block”: 512,  
“model”: “ATA VBOX HARDDISK”,  
“physical\_block”: 512,  
“size”: 12885.0,  
“table”: “msdos”,  
“unit”: “mb”  
},  
“failed”: false,  
“partitions”: [  
{  
“begin”: 1.05,  
“end”: 1200.0,  
“flags”: ,  
“fstype”: “ext4”,  
“name”: “”,  
“num”: 1,  
“size”: 1199.0,  
“unit”: “mb”  
}  
],  
“script”: “unit ‘MB’ print”  
}  
}  
ok: [[ansible3.example.com](http://ansible3.example.com)] =\> {  
“device\_info”: {  
“changed”: false,  
“disk”: {  
“dev”: “/dev/sdb”,  
“logical\_block”: 512,  
“model”: “ATA VBOX HARDDISK”,  
“physical\_block”: 512,  
“size”: 1074.0,  
“table”: “msdos”,  
“unit”: “mb”  
},  
“failed”: false,  
“partitions”: [  
{  
“begin”: 1.05,  
“end”: 800.0,  
“flags”: ,  
“fstype”: “ext4”,  
“name”: “”,  
“num”: 1,  
“size”: 799.0,  
“unit”: “mb”  
}  
],  
“script”: “unit ‘MB’ print”  
}  
}

TASK [Create partition] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [[ansible3.example.com](http://ansible3.example.com)]  
ok: [[ansible2.example.com](http://ansible2.example.com)]

TASK [Print enough size is not available] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [[ansible2.example.com](http://ansible2.example.com)]  
ok: [[ansible3.example.com](http://ansible3.example.com)] =\> {  
“msg”: “Enough size is not available”  
}

TASK [Create 800MB partition] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [[ansible2.example.com](http://ansible2.example.com)]  
ok: [[ansible3.example.com](http://ansible3.example.com)]

TASK [Create file system] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [[ansible3.example.com](http://ansible3.example.com)]: FAILED! =\> {“changed”: false, “cmd”: “/sbin/mkfs.ext4 -F /dev/sdb1”, “msg”: “mke2fs 1.44.6 (5-Mar-2019)\n/dev/sdb1 is mounted; will not make a filesystem here!”, “rc”: 1, “stderr”: “mke2fs 1.44.6 (5-Mar-2019)\n/dev/sdb1 is mounted; will not make a filesystem here!\n”, “stderr\_lines”: [“mke2fs 1.44.6 (5-Mar-2019)”, “/dev/sdb1 is mounted; will not make a filesystem here!”], “stdout”: “”, “stdout\_lines”: }  
fatal: [[ansible2.example.com](http://ansible2.example.com)]: FAILED! =\> {“changed”: false, “cmd”: “/sbin/mkfs.ext4 -F /dev/sdb1”, “msg”: “mke2fs 1.44.6 (5-Mar-2019)\n/dev/sdb1 is mounted; will not make a filesystem here!”, “rc”: 1, “stderr”: “mke2fs 1.44.6 (5-Mar-2019)\n/dev/sdb1 is mounted; will not make a filesystem here!\n”, “stderr\_lines”: [“mke2fs 1.44.6 (5-Mar-2019)”, “/dev/sdb1 is mounted; will not make a filesystem here!”], “stdout”: “”, “stdout\_lines”: }

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[ansible2.example.com](http://ansible2.example.com) : ok=4 changed=0 unreachable=0 failed=1 skipped=2 rescued=0 ignored=0  
[ansible3.example.com](http://ansible3.example.com) : ok=5 changed=0 unreachable=0 failed=1 skipped=1 rescued=0 ignored=0  
[ansible4.example.com](http://ansible4.example.com) : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

Regards,  
Rajesh

---

<div class="post-metadata">

**Author:** ![Rajesh](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@Rajesh](https://forum.ansible.com/u/Rajesh)\
**Post date:** [June 9, 2020, 1:21am UTC](https://forum.ansible.com/t/ansible-playbook-not-printing-the-error-message-when-disk-is-not-defined/33112/2 "2020-06-09T01:21:53Z")

</div>

Could someone please respond? Thanks

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [June 9, 2020, 4:20am UTC](https://forum.ansible.com/t/ansible-playbook-not-printing-the-error-message-when-disk-is-not-defined/33112/3 "2020-06-09T04:20:36Z")

</div>

Your playbook IS printing an error when the disk is not defined. See below

> Hi all,
> 
> The below playbook is not printing an error message when the disk is not defined on a host. Could you please advise if I have made an mistake in the playbook. Thanks
> 
> - name: Create a partition  
> hosts: all  
> become: true  
> become\_user: root  
> tasks:
> 
> - name: Gather disk info  
> parted:  
> device: /dev/sdb  
> unit: MB  
> register: device\_info
> 
> - name: Print disk info  
> debug:  
> var: device\_info
> 
> - name: Create partition  
> parted:  
> device: /dev/sdb  
> number: 1  
> part\_start: 1MB  
> part\_end: 1200MB  
> unit: MB  
> state: present  
> when: device\_info.disk.size \> 1200
> 
> - name: Print enough size is not available  
> debug:  
> msg: “Enough size is not available”  
> when: device\_info.disk.size \< 1200
> 
> - name: Create 800MB partition  
> parted:  
> device: /dev/sdb  
> number: 1  
> part\_start: 1MB  
> part\_end: 800MB  
> unit: MB  
> state: present  
> when: device\_info.disk.size \< 1200
> 
> - name: Create file system  
> filesystem:  
> device: /dev/sdb1  
> fstype: ext4  
> force: yes
> 
> - name: Create /exam directory  
> file:  
> path: /exam  
> state: directory  
> owner: root  
> group: root  
> mode: ‘0755’
> 
> - name: mount File system  
> mount:  
> path: /exam  
> src: /dev/sdb1  
> fstype: ext4  
> state: mounted
> 
> - name: No extra hard disk  
> debug:  
> msg: “No extra hard disk available”  
> when: ansible\_devices.sdb is undefined
> 
> $ ansible-playbook partition.yml
> 
> PLAY [Create a partition] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> ok: [[ansible2.example.com](http://ansible2.example.com)]  
> ok: [[ansible4.example.com](http://ansible4.example.com)]  
> ok: [[ansible3.example.com](http://ansible3.example.com)]
> 
> TASK [Gather disk info] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [[ansible4.example.com](http://ansible4.example.com)]: FAILED! =\> {“changed”: false, “err”: “Error: Could not stat device /dev/sdb - No such file or directory.\n”, “msg”: “Error while getting device information with parted script: ‘/sbin/parted -s -m /dev/sdb – unit ‘MB’ print’”, “out”: “”, “rc”: 1}

^^^^here

---

<div class="post-metadata">

**Author:** ![Rajesh](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@Rajesh](https://forum.ansible.com/u/Rajesh)\
**Post date:** [June 9, 2020, 10:20am UTC](https://forum.ansible.com/t/ansible-playbook-not-printing-the-error-message-when-disk-is-not-defined/33112/4 "2020-06-09T10:20:19Z")

</div>

Thanks for the reply. The playbook is not printing message as per the below task.

- name: No extra hard disk  
debug:  
msg: “No extra hard disk available”  
when: ansible\_devices.sdb is undefined

Thanks,  
Rajesh

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [June 9, 2020, 11:34am UTC](https://forum.ansible.com/t/ansible-playbook-not-printing-the-error-message-when-disk-is-not-defined/33112/5 "2020-06-09T11:34:40Z")

</div>

This is also correct. As the previous failure was already fatal, the  
playbook will stop executing commands for that host  
(ansible4.example.com).  
You can also tell from the play recap.

---

<div class="post-metadata">

**Author:** ![Rajesh](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@Rajesh](https://forum.ansible.com/u/Rajesh)\
**Post date:** [June 9, 2020, 12:26pm UTC](https://forum.ansible.com/t/ansible-playbook-not-printing-the-error-message-when-disk-is-not-defined/33112/6 "2020-06-09T12:26:09Z")

</div>

Thanks again for your help. What needs to be done so that the below play will print the message?

- name: No extra hard disk  
debug:  
msg: “No extra hard disk available”  
when: ansible\_devices.sdb is undefined

Thanks,  
Rajesh

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [June 9, 2020, 4:50pm UTC](https://forum.ansible.com/t/ansible-playbook-not-printing-the-error-message-when-disk-is-not-defined/33112/7 "2020-06-09T16:50:12Z")

</div>

This should be moved all the way up, so that it is the first task.  
Note that the majority of the subsequent tasks assume /dev/sdb is  
available, while this is clearly not the case.  
You should probably revise the playbook and add (more) conditionals.  
For instance, one of the previous outputs you posted shows that the  
playbook tried to create a filesystem on a device that is already  
mounted.  
The logic with 1200MB could also be improved. If the size is \> 1200.  
Create a 1200MB partition - that seems OK.  
But when it's smaller than 1200, create a 800MB partition. What  
happens if the device is less than 800MB?  
Etc etc

---

<div class="post-metadata">

**Author:** ![Rajesh](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@Rajesh](https://forum.ansible.com/u/Rajesh)\
**Post date:** [June 10, 2020, 2:06am UTC](https://forum.ansible.com/t/ansible-playbook-not-printing-the-error-message-when-disk-is-not-defined/33112/8 "2020-06-10T02:06:39Z")

</div>

Thanks Dick. I have modified the playbook and used “block”.

- name: Create partition  
hosts: all  
become: true  
become\_user: root  
tasks:

- name: Gather disk info  
parted:  
device: /dev/sdb  
unit: GB  
register: device\_info  
when: ansible\_devices.sdb is defined

- name: Create 3000MiB partition  
block:

- name: Create 3000MiB partition  
parted:  
device: /dev/sdb  
number: 1  
part\_start: 1MiB  
part\_end: 3000MiB  
state: present  
when: ansible\_devices.sdb1 is not defined

rescue:

- name: Could not create 3000MiB partition  
debug:  
msg: “{{ ansible\_hostname }} does not have sufficient space”  
when: device\_info.disk.size \< 3000

- name: Create 800MiB partition  
parted:  
device: /dev/sdb  
number: 1  
part\_start: 1MiB  
part\_end: 800MiB  
state: present

always:

- name: /dev/sdb doesn’t exist  
debug:  
msg: “/dev/sdb doesn’t exist”  
when: ansible\_devices.sdb is not defined

- name: Create file system  
filesystem:  
dev: /dev/sdb1  
fstype: ext4

- name: Create mountpoint  
file:  
path: /newpart  
state: directory  
owner: root  
group: root  
mode: ‘0755’

- name: Mount the file system  
mount:  
path: /newpart  
src: /dev/sdb1  
fstype: ext4  
state: mounted

$ ansible-playbook partition.yml

PLAY [Create partition] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[ansible4.example.com](http://ansible4.example.com)]  
ok: [[ansible5.example.com](http://ansible5.example.com)]  
ok: [[ansible3.example.com](http://ansible3.example.com)]  
ok: [[ansible2.example.com](http://ansible2.example.com)]

TASK [Gather disk info] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [[ansible5.example.com](http://ansible5.example.com)]  
ok: [[ansible4.example.com](http://ansible4.example.com)]  
ok: [[ansible3.example.com](http://ansible3.example.com)]  
ok: [[ansible2.example.com](http://ansible2.example.com)]

TASK [Create 3000MiB partition] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [[ansible5.example.com](http://ansible5.example.com)]: FAILED! =\> {“changed”: false, “err”: “Error: Could not stat device /dev/sdb - No such file or directory.\n”, “msg”: “Error while getting device information with parted script: ‘/sbin/parted -s -m /dev/sdb – unit ‘KiB’ print’”, “out”: “”, “rc”: 1}  
fatal: [[ansible3.example.com](http://ansible3.example.com)]: FAILED! =\> {“changed”: false, “err”: “Error: The location 3000MiB is outside of the device /dev/sdb.\n”, “msg”: “Error while running parted script: /sbin/parted -s -m -a optimal /dev/sdb – unit KiB mkpart primary 1MiB 3000MiB”, “out”: “”, “rc”: 1}  
changed: [[ansible2.example.com](http://ansible2.example.com)]  
changed: [[ansible4.example.com](http://ansible4.example.com)]

TASK [Could not create 3000MiB partition] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [[ansible5.example.com](http://ansible5.example.com)]: FAILED! =\> {“msg”: “The conditional check ‘device\_info.disk.size \< 3000’ failed. The error was: error while evaluating conditional (device\_info.disk.size \< 3000): ‘dict object’ has no attribute ‘disk’\n\nThe error appears to be in ‘/home/devops/ansible/partition.yml’: line 25, column 10, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n rescue:\n - name: Could not create 3000MiB partition\n ^ here\n”}  
ok: [[ansible3.example.com](http://ansible3.example.com)] =\> {  
“msg”: “ansible3 does not have sufficient space”  
}

TASK [Create 800MiB partition] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [[ansible3.example.com](http://ansible3.example.com)]

TASK [/dev/sdb doesn’t exist] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [[ansible2.example.com](http://ansible2.example.com)]  
ok: [[ansible5.example.com](http://ansible5.example.com)] =\> {  
“msg”: “/dev/sdb doesn’t exist”  
}  
skipping: [[ansible3.example.com](http://ansible3.example.com)]  
skipping: [[ansible4.example.com](http://ansible4.example.com)]

TASK [Create file system] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [[ansible5.example.com](http://ansible5.example.com)]: FAILED! =\> {“changed”: false, “msg”: “Device /dev/sdb1 not found.”}  
ok: [[ansible4.example.com](http://ansible4.example.com)]  
ok: [[ansible3.example.com](http://ansible3.example.com)]  
ok: [[ansible2.example.com](http://ansible2.example.com)]

TASK [Create mountpoint] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[ansible4.example.com](http://ansible4.example.com)]  
ok: [[ansible3.example.com](http://ansible3.example.com)]  
ok: [[ansible2.example.com](http://ansible2.example.com)]

TASK [Mount the file system] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [[ansible3.example.com](http://ansible3.example.com)]  
changed: [[ansible2.example.com](http://ansible2.example.com)]  
changed: [[ansible4.example.com](http://ansible4.example.com)]

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[ansible2.example.com](http://ansible2.example.com) : ok=6 changed=2 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0  
[ansible3.example.com](http://ansible3.example.com) : ok=7 changed=2 unreachable=0 failed=0 skipped=1 rescued=1 ignored=0  
[ansible4.example.com](http://ansible4.example.com) : ok=6 changed=2 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0  
[ansible5.example.com](http://ansible5.example.com) : ok=2 changed=0 unreachable=0 failed=2 skipped=1 rescued=1 ignored=0
