This is currently checking the value of lhost which is undefined. Should be:

 lhost = Rex::Socket.is_ipv6?(datastore['LHOST']) ? "[#{datastore['LHOST']}]" : datastore['LHOST']