def only(name, hostnames):
 ret = {'name': name, 'changes': {}, 'result': None, 'comment': ''}
 if isinstance(hostnames, six.string_types):
  hostnames = [hostnames]
 old = ' '.join(__salt__['hosts.get_alias'](name))
 new = ' '.join((x.strip() for x in hostnames))
 if (old == new):
  ret['comment'] = 'IP address {0} already set to "{1}"'.format(name, new)
  ret['result'] = True
  return ret
 if __opts__['test']:
  ret['comment'] = 'Would change {0} from "{1}" to "{2}"'.format(name, old, new)
  return ret
 ret['result'] = __salt__['hosts.set_host'](name, new)
 if (not ret['result']):
  ret['comment'] = ('hosts.set_host failed to change {0}' + ' from "{1}" to "{2}"').format(name, old, new)
  return ret
 ret['comment'] = 'successfully changed {0} from "{1}" to "{2}"'.format(name, old, new)
 ret['changes'] = {name: {'old': old, 'new': new}}
 return ret

def only ( name , hostnames ) : ret = { 'name' : name , 'changes' : { } , 'result' : None , 'comment' : '' } if isinstance ( hostnames , six . string_types ) : hostnames = [ hostnames ] old = ' ' . join ( __salt__ [ 'hosts.get_alias' ] ( name ) ) new = ' ' . join ( ( x . strip ( ) for x in hostnames ) ) if ( old == new ) : ret [ 'comment' ] = 'IP address {0} already set to "{1}"' . format ( name , new ) ret [ 'result' ] = True return ret if __opts__ [ 'test' ] : ret [ 'comment' ] = 'Would change {0} from "{1}" to "{2}"' . format ( name , old , new ) return ret ret [ 'result' ] = __salt__ [ 'hosts.set_host' ] ( name , new ) if ( not ret [ 'result' ] ) : ret [ 'comment' ] = ( 'hosts.set_host failed to change {0}' + ' from "{1}" to "{2}"' ) . format ( name , old , new ) return ret ret [ 'comment' ] = 'successfully changed {0} from "{1}" to "{2}"' . format ( name , old , new ) ret [ 'changes' ] = { name : { 'old' : old , 'new' : new } } return ret
ensure that only the given hostnames are associated with the given ip address .