Gather Data using ansible playbook

Hello Guys,

Can someone let me know how can we gather filesystem extension from one task and how can we use that result as variable in next task in ansible playbook.? Thanks in advance…

Regard’s
Abhi

I have no idea what a “filesystem extension” is, nor how to gather it.
But once you’ve done that, register it so you can use it in subsequent tasks.

Hi,

Getting below error while using register output in subsequent tasks.

[WARNING]: The value [‘xfs’] (type list) in a string field was converted to u"[‘xfs’]" (type string). If this does not look like what you expect, quote the
entire value to ensure it does not change.
fatal: [stlbnisldaprh01.va.neustar.com]: FAILED! => {“changed”: false, “msg”: “value of fstype must be one of: ext4, ext3, f2fs, btrfs, vfat, ocfs2, ext4dev, swap, reiserfs, lvm, xfs, ext2, got: [‘xfs’]”}

Instead of have people guess what your playbook might look like based on an error, post it

Here I am posting that playbook. please check it and suggest me…

tasks:

  • name: lvm Extend
    shell: “/usr/sbin/lvextend -L +{{ extend_lv_size }} /dev/mapper/{{ vg_name }}-{{ lv_name }}”

  • name: lvm Extend
    shell: “/usr/bin/df -hT | grep {{ Mount_point }} | cut -d. -f1 | awk ‘{print $2}’”
    register: fs

  • name: ‘Extend the FS’
    filesystem:
    fstype: “{{ fs }}”
    dev: “/dev/mapper/{{ vg_name }}-{{ lv_name }}”
    resizefs: yes

  • name: Check Mounted points on hosts
    shell: “df -hT | grep {{ Mount_point }}”
    register: df

  • debug: var=df.stdout_lines

Here I am posting that playbook. please check it and suggest me…

Suggestion 1: don’t use the same meaningless names for several different tasks. Use something that explains what they do.
Suggestion 2: use the lvol module instead of shell commands

The variable you set in the register is an Ansible structure, you cant use it directly like you did here:

  • name: lvm Extend
    shell: “/usr/bin/df -hT | grep {{ Mount_point }} | cut -d. -f1 | awk ‘{print $2}’”
    register: fs

  • name: ‘Extend the FS’
    filesystem:
    fstype: “{{ fs }}”
    dev: “/dev/mapper/{{ vg_name }}-{{ lv_name }}”
    resizefs: yes

You must check the manual and see its structure. In that case, maybe you want “fs.stdout”.

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/shell_module.html

Regards.