File beat installation and configuration with Ansible

Hello,
I’m writing an Ansible script that install and configure filebeat (agent of logstash).

I’ve finished the installation part. Now i need to add the configuration part to the script. I pretty new with Ansible and i need some help.

The user that suppose to run the script will have to select a few groups from a list, and each group from the list contains a few logs paths, which need to be added to the filebeat configuration file.

For example:
Groups to select foe example: redis, nginx, php-fpm

Redis logs:

/var/log/redis/redis.log
/var/log/redis/sentinel.log

Nginx logs:
/var/log/nginx/access.log

/var/log/nginx/error.log

php-fpm logs:
/var/log/php-fpm/error.log

If the user will select redis and php-fpm, these logs will be added to filebeat configuration file (on the remote host), which located on /etc/filebeat/filebeat.yml, under paths section:

`
filebeat:
prospectors:

Here is my example. I am using hash_behaviour = merge.

Layout:
`
├── group_vars
│ ├── php-fpm
│ └── nginx
├── roles
│ └── filebeat
│ ├── defaults
│ │ └── main.yml
│ ├── handlers
│ │ └── main.yml
│ ├── meta
│ │ └── main.yml
│ ├── README.md
│ ├── tasks
│ │ ├── configure.yml
│ │ ├── install.yml
│ │ ├── main.yml
│ │ ├── prepare.yml
│ │ ├── redhat
│ │ │ ├── install.yml
│ │ │ └── prepare.yml
│ │ └── debian
│ │ ├── install.yml
│ │ └── prepare.yml
│ ├── templates
│ │ └── filebeat.yml.j2
│ └── vars

├── debian.yml
│ └── redhat.yml
├── filebeat.yml
└── inventory

`

templates/filebeat.yml.j2:

`
{{ ansible_managed}}
{{ filebeat.options | to_nice_yaml }}

`

tasks/configure.yml:

`