Determine a base path and creating directories in playbooks.

I am trying to create a playbook that, depending on the host, may need to create a series of directories and symlinks.

I know the file command will conditionally create directories and symlinks -- is that the best possible way here though? In general terms it seems inefficient to perform all of those operations every time when they only need to be done occasionally -- when a new server is being added to the inventory. I'm fine with file command solution, I just want to verify that I haven't overlooked something.

Another issue I'm having I'm not coming up with any ideas. These direcotires and symlinks are based off a base path that differs based on their setup, These difference are easily determined on the remote server itself. It's always /data/VCS/something where "something" is a NAS drive identifier. Is there a way I can determine this in a playbook to use to construct my direcorties and symlinks without resorting to manually entering each one as metadata in my inventory?

Any feedback would be appreciated.

Thanks.

<tim/>

I am trying to create a playbook that, depending on the host, may need to create a series of directories and symlinks.

I know the file command will conditionally create directories and symlinks – is that the best possible way here though? In general terms it seems inefficient to perform all of those operations every time when they only need to be done occasionally – when a new server is being added to the inventory. I’m fine with file command solution, I just want to verify that I haven’t overlooked something.

Sure.

This sounds like an excellent time to try out the new tags feature on the development branch.

See examples/playbooks/tags.yml for how everything works.

I also emailed the list about this a couple of days ago.

Another issue I’m having I’m not coming up with any ideas. These direcotires and symlinks are based off a base path that differs based on their setup, These difference are easily determined on the remote server itself. It’s always /data/VCS/something where “something” is a NAS drive identifier. Is there a way I can determine this in a playbook to use to construct my direcorties and symlinks without resorting to manually entering each one as metadata in my inventory?

Yeah this is pretty easy.

Any module can create it’s own fact variables by returning an “ansible_facts” directionally full of variables. You could write a very simple module that returns a variable called foo_path, and then use $foo_path in your playbooks.

Modules can be written in any language, not just Python, and just have to return JSON.

You’ll just have to call the “site_facts” module or whatever you want to call it ahead of the reference to $foo_path, (I’d call it first thing in your playbook) and you should be good to go.

–Michael