|
237 | 237 | type: boolean |
238 | 238 | default: True |
239 | 239 | version_added: "3.6.0" |
| 240 | + oob_ip_as_primary: |
| 241 | + description: Use out of band IP as `ansible host` |
| 242 | + type: boolean |
| 243 | + default: False |
240 | 244 | """ |
241 | 245 |
|
242 | 246 | EXAMPLES = """ |
@@ -812,6 +816,13 @@ def extract_primary_ip6(self, host): |
812 | 816 | except Exception: |
813 | 817 | return |
814 | 818 |
|
| 819 | + def extract_oob_ip(self, host): |
| 820 | + try: |
| 821 | + address = host["oob_ip"]["address"] |
| 822 | + return str(ip_interface(address).ip) |
| 823 | + except Exception: |
| 824 | + return |
| 825 | + |
815 | 826 | def extract_tags(self, host): |
816 | 827 | try: |
817 | 828 | tag_zero = host["tags"][0] |
@@ -1844,6 +1855,10 @@ def _fill_host_variables(self, host, hostname): |
1844 | 1855 | if extracted_primary_ip6: |
1845 | 1856 | self.inventory.set_variable(hostname, "primary_ip6", extracted_primary_ip6) |
1846 | 1857 |
|
| 1858 | + extracted_oob_ip = self.extract_oob_ip(host=host) |
| 1859 | + if extracted_oob_ip and self.oob_ip_as_primary_ip: |
| 1860 | + self.inventory.set_variable(hostname, "ansible_host", extracted_oob_ip) |
| 1861 | + |
1847 | 1862 | for attribute, extractor in self.group_extractors.items(): |
1848 | 1863 | extracted_value = extractor(host) |
1849 | 1864 |
|
@@ -2034,6 +2049,7 @@ def parse(self, inventory, loader, path, cache=True): |
2034 | 2049 | self.cert = self.get_option("cert") |
2035 | 2050 | self.key = self.get_option("key") |
2036 | 2051 | self.ca_path = self.get_option("ca_path") |
| 2052 | + self.oob_ip_as_primary_ip = self.get_option("oob_ip_as_primary_ip") |
2037 | 2053 |
|
2038 | 2054 | self._set_authorization() |
2039 | 2055 |
|
|
0 commit comments