Deploy directory tree: if the tree exists in files-templates - how do I approach host specific files tree conditionally?
Please advise me on an approach I should follow during my implementation of files tree deployment to a target machine, regardless of whether the tree exists or not among files or templates on a control machine.
Should I use a boolean Ansible host variable, like a flag, say, deploy_it equal to false|true to indicate manually that I have a files tree to be copied to a host?
Or can I implement in a task a kind of look-up inside role-name/templates/{{ hostname }}/*/ or role-name/files/{{ hostname }}/*/ to auto-detect if the files tree is present for a particular host’s name? That way I would not have any other flags to be added/changed for a particular host when a host is added to or excluded from the play, other than the files’ presence on the control machine. (I have the exact host name among variables and can insert it into a path to be checked.)
May be templates/{{ hostname }}/*/ or files/{{ hostname }}/*/ at the playbook top-level directory, but that way I am incurring the role files tree (tasks, handlers, defaults and so on) to be split into two places - the role dir. and the top level of the play dir., which I am in doubt about.
Id est:
At control machine, in particular role directory the tree is:
templates
└── dot-config
├── host-name-01
│ └── foo
│ ├── bar-x
│ │ ├── a.conf
│ │ └── b.conf
│ └── bar-y
│ ├── c.conf
│ └── d.conf
└── host-name-02
└── foo
├── bar-x
│ ├── a.conf
│ ├── b.conf
│ └── c.conf
└── bar-y
├── d.conf
├── e.conf
└── f.conf
The parts of the tree above are selected by a host name
and are deployed at target machine as
.config
└── foo
├── bar-x
│ ├── smth-a.conf
│ └── smth-b.conf
└── bar-y
├── smth-c.conf
└── smth-d.conf
What is an optimal approach to launch deploy if the tree exists?
And do not have any other flags to be added/changed for a particular host, when a host is added to or excluded from the play. Files presence at the control machine is the only flag.