|
238 | 238 | type: boolean
|
239 | 239 | default: True
|
240 | 240 | version_added: "3.6.0"
|
| 241 | + oob_ip_as_primary_ip: |
| 242 | + description: Use out of band IP as `ansible host` |
| 243 | + type: boolean |
| 244 | + default: False |
241 | 245 | """
|
242 | 246 |
|
243 | 247 | EXAMPLES = """
|
@@ -820,6 +824,13 @@ def extract_primary_ip6(self, host):
|
820 | 824 | except Exception:
|
821 | 825 | return
|
822 | 826 |
|
| 827 | + def extract_oob_ip(self, host): |
| 828 | + try: |
| 829 | + address = host["oob_ip"]["address"] |
| 830 | + return str(ip_interface(address).ip) |
| 831 | + except Exception: |
| 832 | + return |
| 833 | + |
823 | 834 | def extract_tags(self, host):
|
824 | 835 | try:
|
825 | 836 | tag_zero = host["tags"][0]
|
@@ -1863,6 +1874,10 @@ def _fill_host_variables(self, host, hostname):
|
1863 | 1874 | if extracted_primary_ip6:
|
1864 | 1875 | self.inventory.set_variable(hostname, "primary_ip6", extracted_primary_ip6)
|
1865 | 1876 |
|
| 1877 | + extracted_oob_ip = self.extract_oob_ip(host=host) |
| 1878 | + if extracted_oob_ip and self.oob_ip_as_primary_ip: |
| 1879 | + self.inventory.set_variable(hostname, "ansible_host", extracted_oob_ip) |
| 1880 | + |
1866 | 1881 | for attribute, extractor in self.group_extractors.items():
|
1867 | 1882 | extracted_value = extractor(host)
|
1868 | 1883 |
|
@@ -2053,6 +2068,7 @@ def parse(self, inventory, loader, path, cache=True):
|
2053 | 2068 | self.cert = self.get_option("cert")
|
2054 | 2069 | self.key = self.get_option("key")
|
2055 | 2070 | self.ca_path = self.get_option("ca_path")
|
| 2071 | + self.oob_ip_as_primary_ip = self.get_option("oob_ip_as_primary_ip") |
2056 | 2072 |
|
2057 | 2073 | self._set_authorization()
|
2058 | 2074 |
|
|
0 commit comments