<p dir="auto">Likely caused by <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="203181477" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/20655" data-hovercard-type="pull_request" data-hovercard-url="/ansible/ansible/pull/20655/hovercard" href="https://github.com/ansible/ansible/pull/20655">#20655</a>.</p>
<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<ul dir="auto">
<li>filesystem</li>
</ul>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.3.0
  config file = /opt/ansible/ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.3.0
  config file = /opt/ansible/ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">CONFIGURATION (default)</h5>

<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">CentOS Linux release 7.3.1611 (Core)</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">The filesystem module is used in this case to create an ext4 filesystem on a block device previously created with LVM using the 'lvg' and 'lvol' Ansible modules. When the module queries the target block device for its size, the module returns an exception instead of creating the filesystem (if the filesystem does not exist) or returning no change (if the filesystem already exists).</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">Consider the following task:</p>

<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- name: create {{ volumes_fstype }} filesystems on LVM logical volumes
  filesystem:
    fstype: &quot;{{ volumes_fstype }}&quot;
    resizefs: yes
    dev: /dev/vg{{ item.mount_point | regex_replace('/', '.') }}/lv{{ item.mount_point | regex_replace('/', '.') }}
    force: &quot;{{ force | default(omit) }}&quot;
  with_items: &quot;{{ launch_volumes }}&quot;
  when: ( item.mount_point != '/' ) and
        ( item.volume_size is defined ) and
        ( launch_volumes is defined )"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s">create {{ volumes_fstype }} filesystems on LVM logical volumes</span>
  <span class="pl-ent">filesystem</span>:
    <span class="pl-ent">fstype</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ volumes_fstype }}<span class="pl-pds">"</span></span>
    <span class="pl-ent">resizefs</span>: <span class="pl-s">yes</span>
    <span class="pl-ent">dev</span>: <span class="pl-s">/dev/vg{{ item.mount_point | regex_replace('/', '.') }}/lv{{ item.mount_point | regex_replace('/', '.') }}</span>
    <span class="pl-ent">force</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ force | default(omit) }}<span class="pl-pds">"</span></span>
  <span class="pl-ent">with_items</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ launch_volumes }}<span class="pl-pds">"</span></span>
  <span class="pl-ent">when</span>: <span class="pl-s">( item.mount_point != '/' ) and</span>
        <span class="pl-s">( item.volume_size is defined ) and</span>
        <span class="pl-s">( launch_volumes is defined )</span></pre></div>
<p dir="auto">The task receives its parameters from the <code class="notranslate">launch_volumes</code> dictionary, containing the following values:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="launch_volumes:
  - mount_point: /
    device_name: /dev/sda1
    device_type: gp2
    volume_size: 10
    delete_on_termination: True
  - mount_point: /localvolume
    device_name: /dev/xvdh
    device_type: gp2
    volume_size: 100
    delete_on_termination: True"><pre class="notranslate"><span class="pl-ent">launch_volumes</span>:
  - <span class="pl-ent">mount_point</span>: <span class="pl-s">/</span>
    <span class="pl-ent">device_name</span>: <span class="pl-s">/dev/sda1</span>
    <span class="pl-ent">device_type</span>: <span class="pl-s">gp2</span>
    <span class="pl-ent">volume_size</span>: <span class="pl-c1">10</span>
    <span class="pl-ent">delete_on_termination</span>: <span class="pl-c1">True</span>
  - <span class="pl-ent">mount_point</span>: <span class="pl-s">/localvolume</span>
    <span class="pl-ent">device_name</span>: <span class="pl-s">/dev/xvdh</span>
    <span class="pl-ent">device_type</span>: <span class="pl-s">gp2</span>
    <span class="pl-ent">volume_size</span>: <span class="pl-c1">100</span>
    <span class="pl-ent">delete_on_termination</span>: <span class="pl-c1">True</span></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK [ec2-volumes : create ext4 filesystems on LVM logical volumes] ********************************************************************************************
task path: /opt/ansible/roles/ec2-volumes/tasks/main.yml:31
skipping: [10.233.50.122] =&gt; (item={u'volume_size': 10, u'mount_point': u'/', u'delete_on_termination': True, u'device_type': u'gp2', u'device_name': u'/dev/sda1'})  =&gt; {
    &quot;changed&quot;: false,
    &quot;item&quot;: {
        &quot;delete_on_termination&quot;: true,
        &quot;device_name&quot;: &quot;/dev/sda1&quot;,
        &quot;device_type&quot;: &quot;gp2&quot;,
        &quot;mount_point&quot;: &quot;/&quot;,
        &quot;volume_size&quot;: 10
    },
    &quot;skip_reason&quot;: &quot;Conditional result was False&quot;,
    &quot;skipped&quot;: true
}
Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/filesystem.py
&lt;10.233.50.122&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;10.233.50.122&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/mvaughn/.ansible/cp/
9f8854b6f2 10.233.50.122 '/bin/sh -c '&quot;'&quot;'/usr/bin/python &amp;&amp; sleep 0'&quot;'&quot;''
ok: [10.233.50.122] =&gt; (item={u'volume_size': 100, u'mount_point': u'/localvolume', u'delete_on_termination': True, u'device_type': u'gp2', u'device_name': u'/dev/xvdh'}) =&gt; {
    &quot;changed&quot;: false,
    &quot;invocation&quot;: {
        &quot;module_args&quot;: {
            &quot;dev&quot;: &quot;/dev/vg.localvolume/lv.localvolume&quot;,
            &quot;force&quot;: false,
            &quot;fstype&quot;: &quot;ext4&quot;,
            &quot;opts&quot;: null,
            &quot;resizefs&quot;: true
        }
    },
    &quot;item&quot;: {
        &quot;delete_on_termination&quot;: true,
        &quot;device_name&quot;: &quot;/dev/xvdh&quot;,
        &quot;device_type&quot;: &quot;gp2&quot;,
        &quot;mount_point&quot;: &quot;/localvolume&quot;,
        &quot;volume_size&quot;: 100
    },
    &quot;msg&quot;: &quot;ext4 filesystem is using the whole device /dev/vg.localvolume/lv.localvolume&quot;
}"><pre class="notranslate"><code class="notranslate">TASK [ec2-volumes : create ext4 filesystems on LVM logical volumes] ********************************************************************************************
task path: /opt/ansible/roles/ec2-volumes/tasks/main.yml:31
skipping: [10.233.50.122] =&gt; (item={u'volume_size': 10, u'mount_point': u'/', u'delete_on_termination': True, u'device_type': u'gp2', u'device_name': u'/dev/sda1'})  =&gt; {
    "changed": false,
    "item": {
        "delete_on_termination": true,
        "device_name": "/dev/sda1",
        "device_type": "gp2",
        "mount_point": "/",
        "volume_size": 10
    },
    "skip_reason": "Conditional result was False",
    "skipped": true
}
Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/filesystem.py
&lt;10.233.50.122&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;10.233.50.122&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/mvaughn/.ansible/cp/
9f8854b6f2 10.233.50.122 '/bin/sh -c '"'"'/usr/bin/python &amp;&amp; sleep 0'"'"''
ok: [10.233.50.122] =&gt; (item={u'volume_size': 100, u'mount_point': u'/localvolume', u'delete_on_termination': True, u'device_type': u'gp2', u'device_name': u'/dev/xvdh'}) =&gt; {
    "changed": false,
    "invocation": {
        "module_args": {
            "dev": "/dev/vg.localvolume/lv.localvolume",
            "force": false,
            "fstype": "ext4",
            "opts": null,
            "resizefs": true
        }
    },
    "item": {
        "delete_on_termination": true,
        "device_name": "/dev/xvdh",
        "device_type": "gp2",
        "mount_point": "/localvolume",
        "volume_size": 100
    },
    "msg": "ext4 filesystem is using the whole device /dev/vg.localvolume/lv.localvolume"
}
</code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK [ec2-volumes : create ext4 filesystems on LVM logical volumes] ********************************************************************************************
task path: /opt/ansible/roles/ec2-volumes/tasks/main.yml:31
skipping: [10.233.50.122] =&gt; (item={u'volume_size': 10, u'mount_point': u'/', u'delete_on_termination': True, u'device_type': u'gp2', u'device_name': u'/dev/sda1'})  =&gt; {
    &quot;changed&quot;: false,
    &quot;item&quot;: {
        &quot;delete_on_termination&quot;: true,
        &quot;device_name&quot;: &quot;/dev/sda1&quot;,
        &quot;device_type&quot;: &quot;gp2&quot;,
        &quot;mount_point&quot;: &quot;/&quot;,
        &quot;volume_size&quot;: 10
    },
    &quot;skip_reason&quot;: &quot;Conditional result was False&quot;,
    &quot;skipped&quot;: true
}
Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/filesystem.py
&lt;10.233.50.122&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;10.233.50.122&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/mvaughn/.ansible/cp/
9f8854b6f2 10.233.50.122 '/bin/sh -c '&quot;'&quot;'/usr/bin/python &amp;&amp; sleep 0'&quot;'&quot;''
 [WARNING]: Removed unexpected internal key in module return: _ansible_parsed = False

An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File &quot;/tmp/ansible_fL10VJ/ansible_module_filesystem.py&quot;, line 267, in &lt;module&gt;
    main()
  File &quot;/tmp/ansible_fL10VJ/ansible_module_filesystem.py&quot;, line 219, in main
    devsize_in_bytes = _get_dev_size(dev, module)
  File &quot;/tmp/ansible_fL10VJ/ansible_module_filesystem.py&quot;, line 83, in _get_dev_size
    return int(devsize_in_bytes)
ValueError: invalid literal for int() with base 10: ''

failed: [10.233.50.122] (item={u'volume_size': 100, u'mount_point': u'/localvolume', u'delete_on_termination': True, u'device_type': u'gp2', u'device_name': u'/dev/xvdh'}) =&gt; {
    &quot;failed&quot;: true,
    &quot;item&quot;: {
        &quot;delete_on_termination&quot;: true,
        &quot;device_name&quot;: &quot;/dev/xvdh&quot;,
        &quot;device_type&quot;: &quot;gp2&quot;,
        &quot;mount_point&quot;: &quot;/localvolume&quot;,
        &quot;volume_size&quot;: 100
    },
    &quot;module_stderr&quot;: &quot;Traceback (most recent call last):\n  File \&quot;/tmp/ansible_fL10VJ/ansible_module_filesystem.py\&quot;, line 267, in &lt;module&gt;\n    main()\n  File \&quot;/tmp/ansible_fL10VJ/ansible_module_filesystem.py\&quot;, line 219, in main\n    devsize_in_bytes = _get_dev_size(dev, module)\n  File \&quot;/tmp/ansible_fL10VJ/ansib
le_module_filesystem.py\&quot;, line 83, in _get_dev_size\n    return int(devsize_in_bytes)\nValueError: invalid literal for int() with base 10: ''\n&quot;,
    &quot;module_stdout&quot;: &quot;&quot;,
    &quot;msg&quot;: &quot;MODULE FAILURE&quot;,
    &quot;rc&quot;: 1
}"><pre class="notranslate"><code class="notranslate">TASK [ec2-volumes : create ext4 filesystems on LVM logical volumes] ********************************************************************************************
task path: /opt/ansible/roles/ec2-volumes/tasks/main.yml:31
skipping: [10.233.50.122] =&gt; (item={u'volume_size': 10, u'mount_point': u'/', u'delete_on_termination': True, u'device_type': u'gp2', u'device_name': u'/dev/sda1'})  =&gt; {
    "changed": false,
    "item": {
        "delete_on_termination": true,
        "device_name": "/dev/sda1",
        "device_type": "gp2",
        "mount_point": "/",
        "volume_size": 10
    },
    "skip_reason": "Conditional result was False",
    "skipped": true
}
Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/filesystem.py
&lt;10.233.50.122&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;10.233.50.122&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/mvaughn/.ansible/cp/
9f8854b6f2 10.233.50.122 '/bin/sh -c '"'"'/usr/bin/python &amp;&amp; sleep 0'"'"''
 [WARNING]: Removed unexpected internal key in module return: _ansible_parsed = False

An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_fL10VJ/ansible_module_filesystem.py", line 267, in &lt;module&gt;
    main()
  File "/tmp/ansible_fL10VJ/ansible_module_filesystem.py", line 219, in main
    devsize_in_bytes = _get_dev_size(dev, module)
  File "/tmp/ansible_fL10VJ/ansible_module_filesystem.py", line 83, in _get_dev_size
    return int(devsize_in_bytes)
ValueError: invalid literal for int() with base 10: ''

failed: [10.233.50.122] (item={u'volume_size': 100, u'mount_point': u'/localvolume', u'delete_on_termination': True, u'device_type': u'gp2', u'device_name': u'/dev/xvdh'}) =&gt; {
    "failed": true,
    "item": {
        "delete_on_termination": true,
        "device_name": "/dev/xvdh",
        "device_type": "gp2",
        "mount_point": "/localvolume",
        "volume_size": 100
    },
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_fL10VJ/ansible_module_filesystem.py\", line 267, in &lt;module&gt;\n    main()\n  File \"/tmp/ansible_fL10VJ/ansible_module_filesystem.py\", line 219, in main\n    devsize_in_bytes = _get_dev_size(dev, module)\n  File \"/tmp/ansible_fL10VJ/ansib
le_module_filesystem.py\", line 83, in _get_dev_size\n    return int(devsize_in_bytes)\nValueError: invalid literal for int() with base 10: ''\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE",
    "rc": 1
}
</code></pre></div>
<p dir="auto">Observe that the value <code class="notranslate">devsize_in_bytes</code> evaluates to the empty string, '', which is invalid.</p>
<p dir="auto">That is most likely related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="202409312" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/20551" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/20551/hovercard" href="https://github.com/ansible/ansible/issues/20551">#20551</a></p>
<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">filesystem</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.3.0
  config file = 
  configured module search path = Default w/o overrides
"><pre class="notranslate"><code class="notranslate">ansible 2.3.0
  config file = 
  configured module search path = Default w/o overrides

</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">Default</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<h5 dir="auto">SUMMARY</h5>
<p dir="auto">filesystem module fails on CoreOS with:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="mke2fs 1.42.13 (17-May-2015)\nThe file [/dev/xvdf] does not exist and no size was specified.\n"><pre class="notranslate"><code class="notranslate">mke2fs 1.42.13 (17-May-2015)\nThe file [/dev/xvdf] does not exist and no size was specified.\n
</code></pre></div>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- filesystem: fstype=ext4 dev=/dev/xvdf force=yes"><pre class="notranslate">- <span class="pl-ent">filesystem</span>: <span class="pl-s">fstype=ext4 dev=/dev/xvdf force=yes</span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">Filesystem is created on a given block device.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">Error is thrown.</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: [35.157.42.174]: FAILED! =&gt; {
    &quot;changed&quot;: false, 
    &quot;err&quot;: &quot;mke2fs 1.42.13 (17-May-2015)\nThe file [/dev/xvdf] does not exist and no size was specified.\n&quot;, 
    &quot;failed&quot;: true, 
    &quot;invocation&quot;: {
        &quot;module_args&quot;: {
            &quot;dev&quot;: [
                &quot;/dev/xvdf&quot;
            ], 
            &quot;force&quot;: true, 
            &quot;fstype&quot;: &quot;ext4&quot;, 
            &quot;opts&quot;: null, 
            &quot;resizefs&quot;: false
        }
    }, 
    &quot;msg&quot;: &quot;Creating filesystem ext4 on device '['/dev/xvdf']' failed&quot;, 
    &quot;rc&quot;: 1
}"><pre class="notranslate"><code class="notranslate">fatal: [35.157.42.174]: FAILED! =&gt; {
    "changed": false, 
    "err": "mke2fs 1.42.13 (17-May-2015)\nThe file [/dev/xvdf] does not exist and no size was specified.\n", 
    "failed": true, 
    "invocation": {
        "module_args": {
            "dev": [
                "/dev/xvdf"
            ], 
            "force": true, 
            "fstype": "ext4", 
            "opts": null, 
            "resizefs": false
        }
    }, 
    "msg": "Creating filesystem ext4 on device '['/dev/xvdf']' failed", 
    "rc": 1
}
</code></pre></div>