Coder Social home page Coder Social logo

Comments (3)

cognifloyd avatar cognifloyd commented on June 9, 2024

Maybe one way to do this, would be to allow adding inventory_hostname to hostvar_expressions:

constructable_config_compose = self.get_option('hostvar_expressions')

And do something like:

compose_inventory_hostname = constructable_config_compose.pop("inventory_hostname")

And pass that to get_hostname here:

inventory_hostname = self._get_hostname(h)

inventory_hostname = self._get_hostname(h, compose_inventory_hostname, strict=constructable_config_strict)

Then _get_hostname would change to something like this:

def _get_hostname(self, host, compose=None, strict=False):
    if not compose:
        return host.default_inventory_hostname
    try:
        return self._compose(compose, h.hostvars)
    except Exception as e:
        if strict:
            raise AnsibleParserError("Could not generate inventory_hostname for host %s from hostvar_expressions.inventory_hostname: %s" % (host.default_inventory_hostname, to_native(e)))
        return host.default_inventory_hostname

Any comments on doing it like this? Or would using something other than hostvar_expressions be preferrable?

from azure.

mwinfie avatar mwinfie commented on June 9, 2024

Can a maintainer review this? I think this would solve a similar issue we are having where we want to be able to pull in hosts by ip address instead of the vm name.

from azure.

Fred-sun avatar Fred-sun commented on June 9, 2024

Can a maintainer review this? I think this would solve a similar issue we are having where we want to be able to pull in hosts by ip address instead of the vm name

This PR has been reviewed and will be merged soon. Thank you!

from azure.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.