expect module does not like an int I am passing in

59 views
Skip to first unread message

matt shepherd

unread,
Nov 16, 2016, 12:06:49 PM11/16/16
to Ansible Project
All, I did some searching here and did not find this specific issue. I am trying to use the expect module to work with fdisk to automatically provision new space on VMs.

  tasks:
    - name: "DISK | Create a partition for the added disk space"
      expect:
        command: fdisk /dev/sda
        responses:
          'Command \(m for help*':
            - n
            - t
            - w
          'Select \(default.*$': p
          'Partition number.*$': "{{ next_part }}"
          'First sector.*$': \r
          'Last sector.*$': \r
          'Hex code.*$': 08e

What i get is:

TASK [DISK | Create a partition for the added disk space] **********************
fatal: [p-db-rhel7-01]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to XX.4.XXX.144 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_z0_ZP0/ansible_module_expect.py\", line 237, in <module>\r\n    main()\r\n  File \"/tmp/ansible_z0_ZP0/ansible_module_expect.py\", line 149, in main\r\n    response = u'%s\\n' % value.rstrip('\\n').decode()\r\nAttributeError: 'int' object has no attribute 'rstrip'\r\n", "msg": "MODULE FAILURE"}

I finally figured out that the next_part variable I am passing in is the number of the partition I want to create (3 in this case), and I think this is complaining because there is no "rstrip" function for integers. However, I am sure peopole have used this module to great effect with responses that are integers. So, any help?

Thanks

Kai Stian Olstad

unread,
Nov 16, 2016, 1:10:10 PM11/16/16
to ansible...@googlegroups.com
You could try to filter it to a string
"{{ next_part | string }}"

--
Kai Stian Olstad

matt shepherd

unread,
Nov 17, 2016, 6:33:36 AM11/17/16
to Ansible Project, ansible-pr...@olstad.com
Thanks, I'll have to try that. I actually solved it where I create the variable. What I had in host_vars/node was:

next_part = 3

If I change it to the following it seemed to fix it.

next_part = '3'

Your solution is making use of a feature of jinja, right?

Kai Stian Olstad

unread,
Nov 17, 2016, 10:13:19 AM11/17/16
to ansible...@googlegroups.com
On 17. nov. 2016 12:33, matt shepherd wrote:
> Your solution is making use of a feature of jinja, right?

Yes, Jinja2 filters.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages