You need to make your
fuser_dirname
variable change as you loop over your car models.
Then you need to make your tasks loop over the car models.
- name: Create and copy folder
hosts: all
become_user: fuser
vars_files:
- /ansible_scripts/vars/vars_carmodel_file.yml
vars:
fuser_dirname: "{{ item }}-sample-dir"
tasks:
- name: Create sample directories in /home/mule
ansible.builtin.file:
path: "/home/mule/{{ fuser_dirname }}"
mode: "0755"
state: directory
loop: "{{ car_dirname }}"
- name: Copy /home/fuser directories to /apps
ansible.builtin.copy:
src: "/home/fuser/{{ fuser_dirname }}/"
dest: "/apps/{{ fuser_dirname }}"
loop: "{{ car_dirname }}"
But there's lots of other questionable stuff going on here. The
first task is working in the target hosts
/home/mule
directory, but the second task is copying directories from the
ansible controller's
/home/fuser tree
to the target hosts without specifying group, owner, or mode.
Anyway, this is one answer to how to deal with the looping. You'll
need to work out these other details, though, before you have a
useful process.
Also, use
ansible-lint on your code.