# Ansible from_yaml Filter

The Ansible `from_yaml` filter can be used to simplify data manipulation with formatted data.

An example of the list data type:

### Without a filter
I have to use both `strip` and `split` functions, which is error-prone.

```yaml
glusterfs_node_hostname_base: |
  {% for item in glusterfs_node|unique %}
  {{ hostvars[item].get('ansible_hostname') }}
  {% endfor %}

## gluster requires unique hostname or nodename while probing peers, here glusterfs_node_hostname 
## stores all glusterfs node's hostname for a validation purpose
glusterfs_node_hostname: "{{ glusterfs_node_hostname_base.strip().split('\n') | default([]) }}"
```

### With `from_yaml` filter

```yaml
glusterfs_node_hostname_base: |
  ---
  {% for item in glusterfs_node|unique %}
  - {{ hostvars[item].get('ansible_hostname') }}
  {% endfor %}

## gluster requires unique hostname or nodename while probing peers, here glusterfs_node_hostname 
## stores all glusterfs node's hostname for a validation purpose
glusterfs_node_hostname: "{{ glusterfs_node_hostname_base | from_yaml }}"
```

