Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hostformat host[01:02] not working #8

Closed
rndmh3ro opened this issue Aug 13, 2015 · 8 comments
Closed

hostformat host[01:02] not working #8

rndmh3ro opened this issue Aug 13, 2015 · 8 comments

Comments

@rndmh3ro
Copy link
Contributor

You can specify hosts in the hosts-file the following way:

[test-hosts]
host[01:02]

See here for more info: http://docs.ansible.com/ansible/intro_inventory.html

In the generated overview, this host-pattern is not interpreted but instead shown as a single host (in red color), which does not exist.

@fboender
Copy link
Owner

Hey Sebastian!

I've implemented a host expansion algorithm. It supports numbers ([1:3]), letters ([a:z]) and zero-padding ([01:03]). It also supports multiple patterns in a hostname, though I'm not sure if Ansible even supports that.

Can you verify that this new change fixes your problem? The change has been committed to the master branch, so you'll have to checkout the git repository. If you don't know how to do this, please let me know which method (package) your using to install Ansible-cmdb and I'll whip up a package for you.

Thanks for the bugreport!

Regards,

Ferry

@fboender
Copy link
Owner

Never mind that testing request. I'm reimplementing the host parsing so it'll also do group vars and such. Testing the current implementation would be pointless, since it's changing anyway.

@rndmh3ro
Copy link
Contributor Author

This sounds even better, as this would have been my next feature request!

@fboender
Copy link
Owner

I can't find in the manual how variable precedence works. Would you happen to know? For example, if I have:

[prod]
db01
db02 ansible_ssh_port=8022

[prod:vars]
ansible_ssh_port=6022

Would db02 get a port of 8022 or 6022? I'm assuming more specific definitions override more generic ones (so it would be 8022), but assumption is the mother of you-know-what.

Would you happen to know?

@rndmh3ro
Copy link
Contributor Author

Here's the documentation:
https://docs.ansible.com/ansible/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable

Remember: Child groups override parent groups, and hosts always override their groups.

Your particular case isn't mentioned, but I jsut tested it with this:

[prod]
localhost ansible_connection=ssh ansible_ssh_user=vagrant

[prod:vars]
ansible_connection=ssh ansible_ssh_user=root

The first variable ansible_ssh_user (vagrant) is used, because it is a host-var. When swapping vagrant with root, root is used.
The second var is a group var which has a lower precedence.

EDIT: some more older, unoffical docu:

@fboender
Copy link
Owner

Then they way I implemented it is correct. Thanks for that info!

I've committed a rewrite of the hosts parsing logic to the master branch. It now supports groups of groups and vars groups. I had to fake some data for testing as I don't have an extensive enough hosts definition at my disposal.

Could you test it to see if it works for you?

@rndmh3ro
Copy link
Contributor Author

I just tested it from master-branch and its working! All hosts are displayed!

@fboender
Copy link
Owner

Awesome Sebastian! Thanks for testing it, and thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants