Hello Group,
Requesting for any help and guidance on how I can able to use the variable within the variables.
I have the variable (fuser_dirname) that I’d usually used as the main variable in my playbook. However, I’d just need to have another variable with the list of the car name to make it as directory name.
This maybe similar to the bash script where I will cat the variable file then use the ‘for’ loop command.
Was wondering if anyone may have some idea on how to work this in just playbook module and script.
Below are the command, expected result, variable, and playbook files.
Command
ansible-playbook /ansible_scripts/playbooks/testtemp/for_test_only.yml --limit fuser_hostname
Result
fuserATawscar001:/apps> ls -l
drwxr-xr-x 3 fuser fuser 33 May 30 08:40 honda-sample-dir/
drwxr-xr-x 3 fuser fuser 33 May 30 08:40 tesla-sample-dir/
drwxr-xr-x 3 fuser fuser 33 May 30 08:40 tesla-sample-dir/
Variable File
/ansible_scripts/vars/vars_carmodel_file.yml
car_dirname:
- honda
- toyota
- tesla
Playbook File
- name: Create and copy folder
hosts: all
become_user: fuser
vars_files:
- /ansible_scripts/vars/vars_carmodel_file.yml
vars:
fuser_dirname: (( fuser_folder ))-sample-dir
tasks:
-
name: create
file:
path: “/home/mule/{{ fuser_dirname }}”
mode: 0755
state: directory -
name: copy
copy:
src: “/home/fuser/{{ fuser_dirname }}/”
dest: “/apps/{{ fuser_dirname }}”
Any help and guidance are much appreciated.
Thank you so much in advance.