1

I need to do multiple tasks over one list. So, I created tasks list and include it in the main playbook.
However, it looks like ansible doesn't recognise the tasks list as tasks list, but as playbook:

ERROR! 'set_fact' is not a valid attribute for a Play

main playbook:

---
- name: main playbook
  hosts: all
  tasks:
    - name: subtasks.yaml
      include_tasks: subtasks.yaml
      loop: "{{ names_list }}"
      loop_control:
         loop_var: name

tasks list:

---
- name: "create name for the future vm {{ name }}_{{ ansible_date_time.iso8601 }}"
  set_fact:
     cloned_vm_name: "{{ name }}_{{ ansible_date_time.iso8601 }}"

ansible version : 2.7.5
OS: Ubuntu 16.04.3

Bar
  • 11
  • 1
  • 6

1 Answers1

0

after searching tones online, I found a similar answer for include_role - here and it was life changing!

before:

---
- name: main playbook   
  hosts: all   
  tasks:
    - name: subtasks.yaml
      include_tasks: subtasks.yaml
      loop: "{{ names_list }}"
      loop_control:
         loop_var: name

after:

---
- name: main playbook   
  hosts: all   
  tasks:
    - name: subtasks.yaml
      include_tasks: subtasks.yaml
      vars:
        name: "{{ item }}"
      with_items: "{{ names_list }}"
Bar
  • 11
  • 1
  • 6