You are absolutly on the right track. I incorrectly assumed the issue was
coming from the tags varible. But I tried your suggestion and still got the
same error. So the error is cause just by the group_by and not necessarly
the variable.

I did a group by machine_{{ ansible_machine }} and got the same error.

TASK: [debug msg="machine_{{ ansible_machine }}"]
*****************************
ok: [localhost] => {
    "msg": "machine_x86_64"
}

TASK: [group_by key=machine_{{ ansible_machine }}]
****************************
Traceback (most recent call last):
  File "/usr/local/bin/ansible-playbook", line 324, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/usr/local/bin/ansible-playbook", line 264, in main
    pb.run()
  File "/usr/lib/python2.7/dist-packages/ansible/playbook/__init__.py",
line 348, in run
    if not self._run_play(play):
  File "/usr/lib/python2.7/dist-packages/ansible/playbook/__init__.py",
line 789, in _run_play
    if not self._run_task(play, task, False):
  File "/usr/lib/python2.7/dist-packages/ansible/playbook/__init__.py",
line 497, in _run_task
    results = self._run_task_internal(task, include_failed=include_failed)
  File "/usr/lib/python2.7/dist-packages/ansible/playbook/__init__.py",
line 439, in _run_task_internal
    results = runner.run()
  File "/usr/lib/python2.7/dist-packages/ansible/runner/__init__.py", line
1475, in run
    result_data = self._executor(host, None).result
  File "/usr/lib/python2.7/dist-packages/ansible/runner/__init__.py", line
590, in _executor
    msg = str(ae)
UnicodeEncodeError: 'ascii' codec can't encode character u'\x8b' in
position 20: ordinal not in range(128)


I then did a test to remove the variable and rule out a Jinja templating
issue . So Im grouping by just a word= test. The code is like this

-  group_by: key=test

And the result still looks like this . Same error

TASK: [group_by key=test]
*****************************************************
Traceback (most recent call last):
  File "/usr/local/bin/ansible-playbook", line 324, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/usr/local/bin/ansible-playbook", line 264, in main
    pb.run()
  File "/usr/lib/python2.7/dist-packages/ansible/playbook/__init__.py",
line 348, in run
    if not self._run_play(play):
  File "/usr/lib/python2.7/dist-packages/ansible/playbook/__init__.py",
line 789, in _run_play
    if not self._run_task(play, task, False):
  File "/usr/lib/python2.7/dist-packages/ansible/playbook/__init__.py",
line 497, in _run_task
    results = self._run_task_internal(task, include_failed=include_failed)
  File "/usr/lib/python2.7/dist-packages/ansible/playbook/__init__.py",
line 439, in _run_task_internal
    results = runner.run()
  File "/usr/lib/python2.7/dist-packages/ansible/runner/__init__.py", line
1475, in run
    result_data = self._executor(host, None).result
  File "/usr/lib/python2.7/dist-packages/ansible/runner/__init__.py", line
590, in _executor
    msg = str(ae)
UnicodeEncodeError: 'ascii' codec can't encode character u'\x8b' in
position 20: ordinal not in range(128)



On Fri, May 29, 2015 at 1:29 PM, Toshio Kuratomi <[email protected]>
wrote:

> Hmm... So if I try to replicate this using the debug output of allTags
> directly I'm not able to provoke an error.  Here's my playbook:
>
> ---
> - hosts: localhost
>   vars:
>     allTags:
>       changed: false
>       invocation:
>         module_args: "resource=i-be204f6e region=us-east-1 state=list"
>         module_name: "ec2_tag"
>       play: "setup.yml"
>       role: null
>       state: "ok"
>       tags:
>         Name: "analytics-storm-temp - storm1"
>         environment: "dev"
>         "opsworks:instance": "storm1"
>         "opsworks:layer:storm": "storm"
>         "opsworks:stack": "analytics-storm-temp"
>         role: "storm"
>   tasks:
>   - debug:
>       var: allTags.tags
>   - group_by: key={{ allTags.tags.environment }}
>
> And the output:
>
> $ ansible-playbook tag.yml                               [devel]
> (10:18:12)
>
> PLAY [localhost]
> **************************************************************
>
> GATHERING FACTS
> ***************************************************************
> ok: [localhost]
>
> TASK: [debug ]
> ****************************************************************
> ok: [localhost] => {
>     "var": {
>         "allTags.tags": {
>             "Name": "analytics-storm-temp - storm1",
>             "environment": "dev",
>             "opsworks:instance": "storm1",
>             "opsworks:layer:storm": "storm",
>             "opsworks:stack": "analytics-storm-temp",
>             "role": "storm"
>         }
>     }
> }
>
> TASK: [group_by key={{ allTags.tags.environment }}]
> ***************************
> changed: [localhost]
>
> PLAY RECAP
> ********************************************************************
> localhost                  : ok=3    changed=1    unreachable=0    failed=0
>
>
> If you can see anything about that test that's not applicable to your
> environment, let me know....
>
> Another option might be that the error is occuring in the group_by
> call but the data isn't coming from allTags.tags.
>
> If you do a different group_by does that also cause this same error?
> For instance, taking an example from the documentation:
>
> -  group_by: key=machine_{{ ansible_machine }}
>
>
> -Toshio
>
> On Fri, May 29, 2015 at 9:24 AM, Andres Silva <[email protected]> wrote:
> > Hi Toshio. Thanks a lot for the reply. Here is the debug output of what
> is
> > being returned. Thanks in advance
> >
> > TASK: [debug var=allTags]
> > *****************************************************
> > ok: [localhost] => {
> >     "var": {
> >         "allTags": {
> >             "changed": false,
> >             "invocation": {
> >                 "module_args": "resource=i-be204f6e region=us-east-1
> > state=list",
> >                 "module_name": "ec2_tag"
> >             },
> >             "play": "setup.yml",
> >             "role": null,
> >             "state": "ok",
> >             "tags": {
> >                 "Name": "analytics-storm-temp - storm1",
> >                 "environment": "dev",
> >                 "opsworks:instance": "storm1",
> >                 "opsworks:layer:storm": "storm",
> >                 "opsworks:stack": "analytics-storm-temp",
> >                 "role": "storm"
> >             },
> >             "task": "get environment tag"
> >         }
> >     }
> > }
> >
> > On Fri, May 29, 2015 at 12:14 PM, Toshio Kuratomi <[email protected]
> >
> > wrote:
> >>
> >> I'd be interested to know how that character is getting in there and
> >> what you expect it to be.  u'\x99' seems to be a c1 control character
> >> so it's probably not something that jinja should be expected to
> >> handle.  But the character might originally be a byte in an encoding
> >> that was unexpected that was mangled in the decoding process.  Need
> >> more information about what is being returned as your tags to figure
> >> this out.
> >>
> >> -Toshio
> >>
> >> On Fri, May 29, 2015 at 6:05 AM, Andres Silva <[email protected]> wrote:
> >> > Im running some Ansible playbooks on ec2 instances created by
> OpsWorks.
> >> > Part
> >> > of the automation reads the ec2 tags from the instance. here is the
> code
> >> > for
> >> > that
> >> >
> >> >       - name: gather ec2 facts
> >> >         action: ec2_facts
> >> >
> >> >       - name: get environment tag
> >> >         action: ec2_tag resource={{ ansible_ec2_instance_id }}
> region={{
> >> > ansible_ec2_placement_region }} state=list
> >> >         register: allTags
> >> >
> >> > Using that information I then do a group by using one of the tags. The
> >> > main
> >> > reason to do this is to leverage group_vars and do automation that
> >> > configures settings differently for environments. In this case the tag
> >> > name
> >> > is environment. Code below
> >> >
> >> > - group_by: key={{ allTags.tags.environment }}
> >> >
> >> > All this worked perfectly in Ansible 1.7. But after 1.8 the playbook
> >> > fails
> >> > with the following error. Is intersting to note that the automation
> >> > works
> >> > fine with instances that are not spun up by OpsWorks. OpsWorks does
> add
> >> > some
> >> > special tags to the instance. My suspicion is that some of those tags
> >> > have
> >> > special characters that are causing some sort of unicode issue.
> >> >
> >> > TASK: [group_by key={{ allTags.tags.environment }}]
> >> > ***************************
> >> > fatal: [localhost] => template error while templating string:
> unexpected
> >> > char u'\x99' at 2600
> >> >
> >> > I've tried using quotes in the group_by like this but with the same
> >> > result
> >> >
> >> > - group_by: key="{{ allTags.tags.environment }}"
> >> >
> >> > I also tried using a different way of referencing the dictionary value
> >> > like
> >> > this
> >> >
> >> > - group_by: key={{ allTags['tags']['environment'] }}
> >> >
> >> > But had the same results
> >> >
> >> > I tried the recommendation on this thread
> >> >
> >> >
> https://groups.google.com/forum/#!msg/ansible-project/mLgdORSFspo/PXfO76QNfMMJ
> >> > but still the same issue.
> >> >
> >> > From what I've read there are some changes in Jinja that cause this
> >> > behaviour but I have not been able to figure out the issue. Anyone has
> >> > seen
> >> > this issue or has some recommendations? Thanks in advance
> >> >
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups
> >> > "Ansible Project" group.
> >> > To unsubscribe from this group and stop receiving emails from it, send
> >> > an
> >> > email to [email protected].
> >> > To post to this group, send email to [email protected]
> .
> >> > To view this discussion on the web visit
> >> >
> >> >
> https://groups.google.com/d/msgid/ansible-project/1c943a6b-e424-4443-8d17-eb1f954e97f9%40googlegroups.com
> .
> >> > For more options, visit https://groups.google.com/d/optout.
> >>
> >> --
> >> You received this message because you are subscribed to a topic in the
> >> Google Groups "Ansible Project" group.
> >> To unsubscribe from this topic, visit
> >>
> https://groups.google.com/d/topic/ansible-project/FkW7sXLXoMw/unsubscribe.
> >> To unsubscribe from this group and all its topics, send an email to
> >> [email protected].
> >> To post to this group, send email to [email protected].
> >> To view this discussion on the web visit
> >>
> https://groups.google.com/d/msgid/ansible-project/CAG9juEooeKUca%3De8njCNgL60fkiOdPHs21LDJjDJAugU5D9B%2Bw%40mail.gmail.com
> .
> >> For more options, visit https://groups.google.com/d/optout.
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Ansible Project" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to [email protected].
> > To post to this group, send email to [email protected].
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/ansible-project/CAK%3DcKUtyyJ0ReiFfaUhb5Zh6icFNtRw61UByfhXcNgGmUYR_Cw%40mail.gmail.com
> .
> >
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/FkW7sXLXoMw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAG9juErjPjC0Gkj4R7G8to1tUrdgsJtq-qi965FNL4mzQ24GnQ%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAK%3DcKUsOaFDeXk4VNiy6UbPHtZJ6%2BfzJFFmrd6x6NNANYR8FXg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to