#! /usr/bin/ansible-playbook --- - hosts: localhost connection: local gather_facts: false tasks: - name: add hosts from extra-vars add_host: name: '{{ item }}' groups: building loop: "{{ hosts_list.split('\n') }}" changed_when: false - hosts: building gather_facts: "{{ play_roles_gather_facts | default(false) | bool }}" tasks: - debug: msg="hosts_list={{ hosts_list | replace('\n',',') }}" run_once: true when: play_roles_debug | default(false) | bool - name: Include Ansible roles include_role: name: "{{ role_name }}" loop: "{{ play_roles }}" loop_control: loop_var: role_name when: play_roles is defined