##### SUMMARY
Example here is AWS account ID, which is clearly an integer-like thing. The keyed_group templating logic will error if it gets a type other than a string... but sometime after Ansible 2.9, it seems that I _can't_ cast it to a string

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
lib/ansible/plugins/inventory/__init__.py

##### ANSIBLE VERSION
```
$ ansible --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under
development. This is a rapidly changing source of code and can become unstable at any point.
ansible 2.11.0.dev0
  config file = None
  configured module search path = ['/Users/alancoding/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/alancoding/Documents/repos/ansible/lib/ansible
  ansible collection location = /Users/alancoding/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/alancoding/.virtualenvs/awx_collection/bin/ansible
  python version = 3.7.7 (default, Mar 10 2020, 15:43:03) [Clang 11.0.0 (clang-1100.0.33.17)]
```

##### CONFIGURATION
Defaults

##### OS / ENVIRONMENT
N/A


##### STEPS TO REPRODUCE
Inventory file `aws_ec2.yml`

```yaml
compose:
  ec2_account_id: owner_id
keyed_groups:
- key: ec2_account_id | string
  parent_group: accounts
  prefix: ''
  separator: ''
plugin: amazon.aws.aws_ec2
```

Command:

```
AWS_ACCESS_KEY_ID=<redacted> AWS_SECRET_ACCESS_KEY=<redacted> ANSIBLE_JINJA2_NATIVE=True ansible-inventory -i testing/awx_424_0bzcwopc/aws_ec2.yml --list --export -vvv
```

##### EXPECTED RESULTS
Behavior in 2.9 is that it gives JSON data for the inventory.

I think it also needs to be stated that input variables look like this:

```           
                         "ec2_account_id": "123456789",
                "owner_id": "123456789",
```


##### ACTUAL RESULTS

```
[WARNING]:  * Failed to parse /Users/alancoding/Documents/tower/testing/awx_424_0bzcwopc/aws_ec2.yml with auto plugin: Invalid group name format, expected a string or a list
of them or dictionary, got: <class 'int'>
  File "/Users/alancoding/Documents/repos/ansible/lib/ansible/inventory/manager.py", line 289, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/Users/alancoding/Documents/repos/ansible/lib/ansible/plugins/inventory/auto.py", line 58, in parse
    plugin.parse(inventory, loader, path, cache=cache)
  File "/Users/alancoding/.ansible/collections/ansible_collections/amazon/aws/plugins/inventory/aws_ec2.py", line 644, in parse
    self._populate(results, hostnames)
  File "/Users/alancoding/.ansible/collections/ansible_collections/amazon/aws/plugins/inventory/aws_ec2.py", line 534, in _populate
    self._add_hosts(hosts=groups[group], group=group, hostnames=hostnames)
  File "/Users/alancoding/.ansible/collections/ansible_collections/amazon/aws/plugins/inventory/aws_ec2.py", line 569, in _add_hosts
    self._add_host_to_keyed_groups(self.get_option('keyed_groups'), host, hostname, strict=strict)
  File "/Users/alancoding/Documents/repos/ansible/lib/ansible/plugins/inventory/__init__.py", line 431, in _add_host_to_keyed_groups
    raise AnsibleParserError("Invalid group name format, expected a string or a list of them or dictionary, got: %s" % type(key))
```

No matter what I do, it doesn't seem to use this as a string.

Presumably, this may be something that can be reproduced with the constructed inventory plugin by itself, but I have not gotten that far yet.

So something is forcing this into an integer, and it wasn't there is 2.9. That's about the extent of what I know at this point.

The string inside of the {{ gets interpreted multiple times First by yaml.
    Then by python.  And finally by jinja2 as part of it's variable.  Because
    it is processed by both python and jinja2, the backslash escaped
    characters get unescaped twice.  This means that we'd normally have to use
    four backslashes to escape that.  This is painful for playbook authors as
    they have to remember different rules for inside vs outside of a jinja2
    expression (The backslashes outside of the "{{ }}" only get processed by
    yaml and python.  So they only need to be escaped once).  The following
    code fixes this by automatically performing the extra quoting of
    backslashes inside of a jinja2 expression.
    """
    if '\\' in data and '{{' in data:
        new_data = []
        d2 = jinja_env.preprocess(data)
        in_var = False
        for token in jinja_env.lex(d2):
            if token[1] == 'variable_begin':
                in_var = True
                new_data.append(token[2])
            elif token[1] == 'variable_end':
                in_var = False
                new_data.append(token[2])
            elif in_var and token[1] == 'string':
                
                new_data.append(token[2].replace('\\', '\\\\'))
            else:
                new_data.append(token[2])
        data = ''.join(new_data)
    return data
def is_template(data, jinja_env):