Repository: openshift/openshift-ansible

Issue:
[openstack method] ERROR: The Parameter (dns_image) was not provided
Apparently after fixes in this commit: https://github.com/openshift/openshift-ansible/commit/0cd7191cd788d2e6b0ec8d3c5f52562433ed8a13

I'm not able to spin up a new openstack cluster and have to checkout tag openshift-ansible-3.4.17-1 to get it to work

##### Version
latest head

##### Steps To Reproduce
1. Run openstack method

a la:

```
bin/cluster create   -o image_name=centos-timezone   -o external_net=ext-net   -o floating_ip_pool=ext-net   -o net_cidr=40.0.0.0/24   openstack test_cluster
```



##### Current Result

Short version: `ERROR: The Parameter (dns_image) was not provided.`

```
[stack@undercloud openshift-ansible]$ bin/cluster create   -o image_name=centos-timezone   -o external_net=ext-net   -o floating_ip_pool=ext-net   -o net_cidr=40.0.0.0/24   openstack test_cluster
================================================================================
ATTENTION: You are running a community supported utility that has not been
tested by Red Hat. Visit https://docs.openshift.com for supported installation
instructions.
================================================================================


PLAY [Launch instance(s)] ******************************************************

TASK [Check OpenStack stack] ***************************************************
ok: [localhost]

TASK [set_fact] ****************************************************************
ok: [localhost]

TASK [set_fact] ****************************************************************
skipping: [localhost]

TASK [Create or Update OpenStack Stack] ****************************************
fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["heat", "stack-create", "-f", "files/heat_stack.yaml", "--timeout", "10", "-P", "cluster_env=dev", "-P", "cluster_id=test_cluster", "-P", "subnet_24_prefix=192.168.133", "-P", "dns_nameservers=8.8.8.8,8.8.4.4", "-P", "external_net=ext-net", "-P", "ssh_public_key=ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCa2KmP2Th4FZ407XsD1Is3Ur0mxRirNdOx7mzqNHctNm+bWOzhBTExwFroJMokqhuLzxKcfwzje+LiS/qA7+YPVlg4Ivluy4a+TuLloA6XlBLBZl7RlqTR1qypIL48avf947lsfFCv63EtC1LfLYr0dofG+7kjM4eJO2KaiZ5DLIx/lWZdjcRieggX+UQx9KllYyaAfCvK1L+NgOEGTVDsrAkpoEkN5EKOfSGlaiKUz31dCYYNjFkg/xhnwbR60QmuOwAAkwGGBGdPExIEq7Ox9JvJDONP/L761usuLWwMpD7JYlspLqBIAaXs0E46Pd2o0qileIJtO7xEF7LuqnCd stack@undercloud.localdomain", "-P", "ssh_incoming=0.0.0.0/0", "-P", "node_port_incoming=0.0.0.0/0", "-P", "num_etcd=0", "-P", "num_masters=1", "-P", "num_nodes=2", "-P", "num_infra=1", "-P", "etcd_image=centos-timezone", "-P", "master_image=centos-timezone", "-P", "node_image=centos-timezone", "-P", "infra_image=centos-timezone", "-P", "etcd_flavor=m1.small", "-P", "master_flavor=m1.small", "-P", "node_flavor=m1.medium", "-P", "infra_flavor=m1.small", "openshift-ansible-test_cluster-stack"], "delta": "0:00:02.940296", "end": "2016-11-08 20:59:47.725261", "failed": true, "rc": 1, "start": "2016-11-08 20:59:44.784965", "stderr": "ERROR: The Parameter (dns_image) was not provided.", "stdout": "", "stdout_lines": [], "warnings": []}

```
##### Expected Result

Network and nova hosts created without error.

##### Additional Information
Exact command above.
Centos 7.2



Discussion:

Resolving patch:
diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py
--- a/roles/openshift_facts/library/openshift_facts.py
+++ b/roles/openshift_facts/library/openshift_facts.py
@@ -148,6 +148,7 @@ def hostname_valid(hostname):
     if (not hostname or
             hostname.startswith('localhost') or
             hostname.endswith('localdomain') or
+            hostname.endswith('novalocal') or
             len(hostname.split('.')) < 2):
         return False
 
@@ -362,12 +363,15 @@ def normalize_openstack_facts(metadata, facts):
     facts['network']['ip'] = local_ipv4
     facts['network']['public_ip'] = metadata['ec2_compat']['public-ipv4']
 
-    # TODO: verify local hostname makes sense and is resolvable
-    facts['network']['hostname'] = metadata['hostname']
-
-    # TODO: verify that public hostname makes sense and is resolvable
-    pub_h = metadata['ec2_compat']['public-hostname']
-    facts['network']['public_hostname'] = pub_h
+    for f_var, h_var, ip_var in [('hostname',        'hostname',        'local-ipv4'),
+                                 ('public_hostname', 'public-hostname', 'public-ipv4')]:
+        try:
+            if socket.gethostbyname(metadata['ec2_compat'][h_var]) == metadata['ec2_compat'][ip_var]:
+                facts['network'][f_var] = metadata['ec2_compat'][h_var]
+            else:
+                facts['network'][f_var] = metadata['ec2_compat'][ip_var]
+        except socket.gaierror:
+            facts['network'][f_var] = metadata['ec2_compat'][ip_var]
 
     return facts
 
@@ -936,6 +940,14 @@ def set_sdn_facts_if_unset(facts, system_facts):
 
     return facts
 
+def set_nodename(facts):
+    if 'node' in facts and 'common' in facts:
+        if 'cloudprovider' in facts and facts['cloudprovider']['kind'] == 'openstack':
+            facts['node']['nodename'] = facts['provider']['metadata']['hostname'].replace('.novalocal', '')
+        else:
+            facts['node']['nodename'] = facts['common']['hostname'].lower()
+    return facts
+
 def migrate_oauth_template_facts(facts):
     """
     Migrate an old oauth template fact to a newer format if it's present.
@@ -1312,7 +1324,7 @@ def apply_provider_facts(facts, provider_facts):
 
         facts['common'][h_var] = choose_hostname(
             [provider_facts['network'].get(h_var)],
-            facts['common'][ip_var]
+            facts['common'][h_var]
         )
 
     facts['provider'] = provider_facts
@@ -1795,6 +1807,7 @@ def generate_facts(self,
         facts = set_proxy_facts(facts)
         if not safe_get_bool(facts['common']['is_containerized']):
             facts = set_installed_variant_rpm_facts(facts)
+        facts = set_nodename(facts)
         return dict(openshift=facts)
 
     def get_defaults(self, roles, deployment_type, deployment_subtype):


Test patch: