<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Also test if the latest release and devel branch are affected too -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
<!--- Explain the problem briefly below -->
`unique` filter does not respect the order and gives non-idempotent results

##### ISSUE TYPE
- Bug Report


##### COMPONENT NAME
lib/ansible/plugins/filter/mathstuff.py


##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```paste below
ansible 2.8.5
```

##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->
I have the following statement in my template 

```jinja2
{% for host in url_list | map('urlsplit', 'hostname') | unique %}
    upstream {{ host }} {
        server {{ host }}:443;
        keepalive 20;
        keepalive_requests 500;
        keepalive_timeout 30s;
    }
{% endfor %}
```

which basically extracts unique host names from some url list and declares upstream server for each. 

##### EXPECTED RESULTS
The order of hosts is at least consistent between runs. 


##### ACTUAL RESULTS
The order of hosts is different for each run. Unexpected handlers are triggered.

#
#
#
#
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import itertools
import math
from jinja2.filters import environmentfilter
from ansible.errors import AnsibleFilterError, AnsibleFilterTypeError
from ansible.module_utils.common.text import formatters
from ansible.module_utils.six import binary_type, text_type
from ansible.module_utils.six.moves import zip, zip_longest
from ansible.module_utils.common._collections_compat import Hashable, Mapping, Iterable
from ansible.module_utils._text import to_native, to_text
from ansible.utils.display import Display
try:
    from jinja2.filters import do_unique
    HAS_UNIQUE = True
except ImportError:
    HAS_UNIQUE = False
try:
    from jinja2.filters import do_max, do_min
    HAS_MIN_MAX = True
except ImportError:
    HAS_MIN_MAX = False
display = Display()
@environmentfilter
def unique(environment, a, case_sensitive=False, attribute=None):