So I have a playbook that installs gitlab. The playbook includes a role that optionally installs ssl certificates. The ssl certificates are obviously something I want to be customizable. Is there a better way to get the path than breaking out of the role using …/ ?
I am doing this::
ssl_certs_src_glob: ../../../.private/files/null/ssl/certs/*
ssl_keys_src_glob: ../../../.private/files/null/ssl/keys/*
It works, I was just wondering if there was a cleaner way.
Built-in variables like “inventory_dir” can give you the location of the inventory file.
http://www.ansibleworks.com/docs/playbooks2.html#id7
There is no current directory to signify the playbook base directory, however (patches would be welcome!)
For now, I would likely avoid repeating yourself by defining something like:
ssl_dir: …/…/.private
ssl_certs_src_glob: “{{ ssl_dir }}/files/null/ssl/certs/*”
That way you don’t have to repeat the “…/” everywhere.
Cool, thanks for the info Michael. I’ll try to find some time to see about adding a base directory, though can’t promise a pull request. Maybe it is just good enough as is anyway.
Thanks again!
If you want to file a feature request ticket in github, someone might come along and make it happen too
I’ve tried that variable but it seems to not provide what’s expected - I’m on the latest dev-release of Ansible from github.
When using this in a roles/ROLENAME/defaults/main.yml:
password: “{{ lookup(‘password’, ‘./’ + inventory_dir + ‘/files/’ + inventory_hostname + ‘/password length=16’ ) }}”
Then I’m getting a file named roles/ROLENAME/PATH_TO_INVENTORY/files/HOSTNAME/password
My structure is:
root
- inventories
- company1
- company2
- company3
- scripts
- script1
- script2
- script3
- playbooks
- pb1.yml
- pb2.yml
- pb3.yml
- roles
- role1
- role2
- role3
I’m calling ansible-playbook from within the directory root/scripts like this:
ansible-playbook -i …/inventories/company1/hosts …/playbooks/pb1
I was expecting the file to be called root/inventories/company1/files/HOSTNAME/password but it isn’t.
Not: in the lookup I tried with and without the leading ‘./’ and both result in the same file name in the end.
“'ve tried that variable but it seems to not provide what’s expected”
It’s an absolute path, don’t prefix it with a relative one.
What do you mean by this being an absolute path? What I’m getting is “inventories/company1” but no glue where this is in the full directory tree.
ok so /root is an absolute path
you would never say “.//root” to use that path.
Just like you wouldn’t say ‘./’ + inventory_dir
Because inventory_dir is an absolute path.
Yes, I agree that /root is an absolute path. But what I get for onventory_dir is “inventories/customer1” and I would expect to get “/root/inventories/customer1” because then I would exactly know where to go. But with only “inventories/customer1” I don’t.
If you do not see the inventory directory as an absolute path on 1.3.X please file a bug.
@Michael DeHaan, I have just commented on the closed issue 4291 and wonder if you could please have another look there.
Not sure if you’re getting notifications while the issue is already closed, but I have responded there yesterday and provided all the details to reproduce the problem.
Notifications on closed tickets are typically not read or responded to.
If you believe something is still a problem, please open a ticket with a link to a gist or github repo that reproduces the problem.
It is so easy to clobber formatting of content in the github comment box.
Understood. All available as https://github.com/ansible/ansible/issues/4535 including the link to the gist and a screenshot.