@@ -55,20 +55,20 @@ func gatherResources(s *state) map[string]interface{} {
5555
5656 for _ , res := range s .resources () {
5757 // place in list of all resources
58- all .Hosts = appendUniq (all .Hosts , res .Address ())
58+ all .Hosts = appendUniq (all .Hosts , res .Hostname ())
5959
6060 // place in list of resource types
6161 tp := fmt .Sprintf ("type_%s" , res .resourceType )
62- types [tp ] = appendUniq (types [tp ], res .Address ())
62+ types [tp ] = appendUniq (types [tp ], res .Hostname ())
6363
6464 unsortedOrdered [res .baseName ] = append (unsortedOrdered [res .baseName ], res )
6565
6666 // store as invdividual host (eg. <name>.<count>)
6767 invdName := fmt .Sprintf ("%s.%d" , res .baseName , res .counter )
6868 if old , exists := individual [invdName ]; exists {
69- fmt .Fprintf (os .Stderr , "overwriting already existing individual key %s, old: %v, new: %v" , invdName , old , res .Address ())
69+ fmt .Fprintf (os .Stderr , "overwriting already existing individual key %s, old: %v, new: %v" , invdName , old , res .Hostname ())
7070 }
71- individual [invdName ] = []string {res .Address ()}
71+ individual [invdName ] = []string {res .Hostname ()}
7272
7373 // inventorize tags
7474 for k , v := range res .Tags () {
@@ -77,7 +77,7 @@ func gatherResources(s *state) map[string]interface{} {
7777 if v != "" {
7878 tag = fmt .Sprintf ("%s_%s" , k , v )
7979 }
80- tags [tag ] = appendUniq (tags [tag ], res .Address ())
80+ tags [tag ] = appendUniq (tags [tag ], res .Hostname ())
8181 }
8282 }
8383
@@ -94,7 +94,7 @@ func gatherResources(s *state) map[string]interface{} {
9494 sort .Sort (cs )
9595
9696 for i := range resources {
97- ordered [basename ] = append (ordered [basename ], resources [i ].Address ())
97+ ordered [basename ] = append (ordered [basename ], resources [i ].Hostname ())
9898 }
9999 }
100100
@@ -187,8 +187,10 @@ func checkErr(err error, stderr io.Writer) int {
187187
188188func cmdHost (stdout io.Writer , stderr io.Writer , s * state , hostname string ) int {
189189 for _ , res := range s .resources () {
190- if hostname == res .Address () {
191- return output (stdout , stderr , res .Attributes ())
190+ if hostname == res .Hostname () {
191+ attributes := res .Attributes ()
192+ attributes ["ansible_host" ] = res .Address ()
193+ return output (stdout , stderr , attributes )
192194 }
193195 }
194196
0 commit comments