--- - name: Combine service lists for bash script set_fact: service_list: "{{ service_list | default('') +'\"' + item + '\" ' }}" with_items: - "{{ status_services }}" - name: Install statusservices script template: src: statusservices.j2 dest: /usr/local/bin/statusservices owner: root group: root mode: '0755' when: - service_list is defined - name: Add statusservices to .bash_profile lineinfile: path: /root/.bash_profile line: '/usr/local/bin/statusservices' state: present when: - service_list is defined