@@ -120,76 +120,66 @@ def skms(args):
120120
121121 # step through device services to add them as groups
122122 for device_service in info ['device_service' ]:
123- device_service = device_service .replace (
124- device_service_strip , '' ).encode ('utf-8' )
123+ device_service = device_service .replace (device_service_strip , '' )
125124
126125 # add device service to top-level dictionary as a group
127126 if device_service not in dictionary_of_hosts :
128127 dictionary_of_hosts [device_service ] = {"hosts" : []}
129128 # add host to array of that device service group
130129 if info ['name' ] not in dictionary_of_hosts [device_service ]['hosts' ]:
131- dictionary_of_hosts [device_service ]['hosts' ].append (
132- info ['name' ].encode ('utf-8' ))
130+ dictionary_of_hosts [device_service ]['hosts' ].append (info ['name' ])
133131
134132 # add environment to top-level dictionary as a group
135133 if info ['environment' ] not in dictionary_of_hosts :
136- dictionary_of_hosts [info ['environment' ].encode (
137- 'utf-8' )] = {"hosts" : []}
134+ dictionary_of_hosts [info ['environment' ]] = {"hosts" : []}
138135 # add host to array of that environment group
139136 if info ['name' ] not in dictionary_of_hosts [info ['environment' ]]['hosts' ]:
140- dictionary_of_hosts [info ['environment' ]]['hosts' ].append (
141- info ['name' ].encode ('utf-8' ))
137+ dictionary_of_hosts [info ['environment' ]]['hosts' ].append (info ['name' ])
142138
143139 # add primary_ip_address to top-level dictionary as a group
144140 if info ['primary_ip_address' ] not in dictionary_of_hosts :
145- dictionary_of_hosts [info ['primary_ip_address' ].encode (
146- 'utf-8' )] = {"hosts" : []}
141+ dictionary_of_hosts [info ['primary_ip_address' ]] = {"hosts" : []}
147142 if info ['name' ] not in dictionary_of_hosts [info ['primary_ip_address' ]]['hosts' ]:
148- dictionary_of_hosts [info ['primary_ip_address' ]
149- ]['hosts' ].append (info ['name' ].encode ('utf-8' ))
143+ dictionary_of_hosts [info ['primary_ip_address' ]]['hosts' ].append (info ['name' ])
150144
151145 # add owner to top-level dictionary as a group
152146 if info ['owner' ] not in dictionary_of_hosts :
153- dictionary_of_hosts [info ['owner' ]. encode ( 'utf-8' ) ] = {"hosts" : []}
147+ dictionary_of_hosts [info ['owner' ]] = {"hosts" : []}
154148 if info ['name' ] not in dictionary_of_hosts [info ['owner' ]]['hosts' ]:
155- dictionary_of_hosts [info ['owner' ]]['hosts' ].append (
156- info ['name' ].encode ('utf-8' ))
149+ dictionary_of_hosts [info ['owner' ]]['hosts' ].append (info ['name' ])
157150
158151 # add site to top-level dictionary as a group
159152 if info ['site' ] not in dictionary_of_hosts :
160- dictionary_of_hosts [info ['site' ]. encode ( 'utf-8' ) ] = {"hosts" : []}
153+ dictionary_of_hosts [info ['site' ]] = {"hosts" : []}
161154 if info ['name' ] not in dictionary_of_hosts [info ['site' ]]['hosts' ]:
162- dictionary_of_hosts [info ['site' ]]['hosts' ].append (
163- info ['name' ].encode ('utf-8' ))
155+ dictionary_of_hosts [info ['site' ]]['hosts' ].append (info ['name' ])
164156
165157 # add cluster to top-level dictionary as a group
166158 if info ['cluster' ] not in dictionary_of_hosts :
167- dictionary_of_hosts [info ['cluster' ].encode (
168- 'utf-8' )] = {"hosts" : []}
159+ dictionary_of_hosts [info ['cluster' ]] = {"hosts" : []}
169160 if info ['name' ] not in dictionary_of_hosts [info ['cluster' ]]['hosts' ]:
170- dictionary_of_hosts [info ['cluster' ]]['hosts' ].append (
171- info ['name' ].encode ('utf-8' ))
161+ dictionary_of_hosts [info ['cluster' ]]['hosts' ].append (info ['name' ])
172162
173163 # tie some extra information to hostname in the meta variables
174- dictionary_of_hosts ['_meta' ]['hostvars' ][info ['name' ]. encode ( 'utf-8' ) ] = {
175- 'ec2_id' : info ['device_id' ]. encode ( 'utf-8' ) ,
176- 'ansible_ssh_host' : info ['primary_ip_address' ]. encode ( 'utf-8' ) ,
177- 'ansible_host' : info ['primary_ip_address' ]. encode ( 'utf-8' ) ,
178- 'computer_name' : info ['computer_name' ]. encode ( 'utf-8' ) ,
179- 'location' : info ['location_name' ]. encode ( 'utf-8' ) ,
180- 'name' : info ['name' ].split ('.' )[0 ]. encode ( 'utf-8' ) ,
181- 'operating_system' : info ['operating_system' ]. encode ( 'utf-8' ) ,
182- 'private_ip' : info ['primary_ip_address' ]. encode ( 'utf-8' ) ,
164+ dictionary_of_hosts ['_meta' ]['hostvars' ][info ['name' ]] = {
165+ 'ec2_id' : info ['device_id' ],
166+ 'ansible_ssh_host' : info ['primary_ip_address' ],
167+ 'ansible_host' : info ['primary_ip_address' ],
168+ 'computer_name' : info ['computer_name' ],
169+ 'location' : info ['location_name' ],
170+ 'name' : info ['name' ].split ('.' )[0 ],
171+ 'operating_system' : info ['operating_system' ],
172+ 'private_ip' : info ['primary_ip_address' ],
183173 'tags' : {
184- 'Adobe:Environment' : info ['environment' ]. encode ( 'utf-8' ) ,
185- 'Adobe:Owner' : info ['owner' ]. encode ( 'utf-8' ) ,
186- 'CMDB_device_service' : device_service . encode ( 'utf-8' ) ,
187- 'CMDB_environment' : info ['environment' ]. encode ( 'utf-8' ) ,
188- 'CMDB_hostname' : info ['name' ].split ('.' )[0 ]. encode ( 'utf-8' ) ,
189- 'cluster' : info ['cluster' ]. encode ( 'utf-8' ) ,
190- 'environment' : info ['environment' ]. encode ( 'utf-8' ) ,
191- 'role' : device_service . encode ( 'utf-8' ) ,
192- 'site' : info ['site' ]. encode ( 'utf-8' ) ,
174+ 'Adobe:Environment' : info ['environment' ],
175+ 'Adobe:Owner' : info ['owner' ],
176+ 'CMDB_device_service' : device_service ,
177+ 'CMDB_environment' : info ['environment' ],
178+ 'CMDB_hostname' : info ['name' ].split ('.' )[0 ],
179+ 'cluster' : info ['cluster' ],
180+ 'environment' : info ['environment' ],
181+ 'role' : device_service ,
182+ 'site' : info ['site' ],
193183 }
194184 }
195185
0 commit comments