@@ -849,12 +849,30 @@ def get_diff_replace_delete(self):
849
849
850
850
diff_delete = []
851
851
852
+ def check_have_c_in_want_list (have_c ):
853
+ for want_c in self .want_create :
854
+ if have_c ["switches" ][0 ]["ipaddr" ] == want_c ["switches" ][0 ]["ipaddr" ]:
855
+ return True
856
+
857
+ return False
858
+
852
859
def have_in_want (have_c ):
853
860
match_found = False
861
+
862
+ # Check to see if have is in the want list and if not return match_found(False)
863
+ if not check_have_c_in_want_list (have_c ):
864
+ return match_found
854
865
for want_c in self .want_create :
855
866
match = re .search (r"\S+\((\S+)\)" , want_c ["switches" ][0 ]["deviceIndex" ])
856
867
if match is None :
857
- continue
868
+ # If we get here this is typically because the device was pre-provisioned
869
+ # and the regex expression above will not match in this case.
870
+ # We need to make an additionl check using ipaddr to see if the device
871
+ # is already part of the fabric.
872
+ if have_c ["switches" ][0 ]["ipaddr" ] == want_c ["switches" ][0 ]["ipaddr" ]:
873
+ match = re .search (r"\S+\((\S+)\)" , have_c ["switches" ][0 ]["deviceIndex" ])
874
+ if match is None :
875
+ return match_found
858
876
want_serial_num = match .groups ()[0 ]
859
877
if have_c ["switches" ][0 ]["serialNumber" ] == want_serial_num :
860
878
if (
@@ -883,7 +901,6 @@ def have_in_want(have_c):
883
901
def get_diff_delete (self ):
884
902
885
903
diff_delete = []
886
-
887
904
if self .config :
888
905
for want_c in self .want_create :
889
906
for have_c in self .have_create :
@@ -905,8 +922,21 @@ def get_diff_merge(self):
905
922
found = False
906
923
match = re .search (r"\S+\((\S+)\)" , want_c ["switches" ][0 ]["deviceIndex" ])
907
924
if match is None :
908
- msg = "Switch with IP {0} is not reachable or is not a valid IP" .format (want_c ["seedIP" ])
909
- self .module .fail_json (msg = msg )
925
+ # If we don't have a match that means one of the following:
926
+ # (1) The device has not been discovered and is not reachable or the IP address is not a valid IP
927
+ # (2) The device has been discovered and added to the fabric but is currently not reachable
928
+ # due to it being pre-provisioned or some other reason.
929
+ want_c_already_discovered = False
930
+ for have_c in self .have_create :
931
+ # Check the have list to see if the device has already been discovered and if so
932
+ # don't error but use the have list to create the match.
933
+ if have_c ["switches" ][0 ]["ipaddr" ] == want_c ["switches" ][0 ]["ipaddr" ]:
934
+ want_c_already_discovered = True
935
+ match = re .search (r"\S+\((\S+)\)" , have_c ["switches" ][0 ]["deviceIndex" ])
936
+ # Device is not part of the fabric so return the error.
937
+ if not want_c_already_discovered :
938
+ msg = "Switch with IP {0} is not reachable or is not a valid IP" .format (want_c ["seedIP" ])
939
+ self .module .fail_json (msg = msg )
910
940
serial_num = match .groups ()[0 ]
911
941
for have_c in self .have_create :
912
942
if (
0 commit comments