Score:0

Cannot combine looped variables

cn flag

I have well over a dozen jobs within AWX, but given the following code only returns one job name:

- name: Set job_name(s) as facts for limiting job rename
  set_fact:
    job: "{{ job_name|default([]) + [ {
      'name': item['name']
      } ] }}"
  loop: "{{ query('awx.awx.controller_api', 'job_templates', host=awx_host,
                     username=awx_user, password=awx_pass, verify_ssl=False) }}"
  loop_control:
    label: "{{ item['name'] }}"

- debug:
    msg: '{{ item.name }}'
  with_items: '{{ job }}'

Actual results (but expect to see all job names):

TASK [cfg_actions : debug] *****************************************************
   ok: [localhost] => (item={'name': 'Job name 1'}) => {
   "msg": "Job name 1"
   }

It seems this should be fairly simple but I cannot seem to figure out what is missing. Is there a general practice for combining lists without using 'join', as 'join' often splits all letters of a variable with commas (rather than joining the variables).

Thanks in advance for any help.

br flag
Try this: `job: "{{ job|default([]) + [{'name': item['name']}] }}"`
cn flag
Yes, worked perfectly! You're always so helpful Vladimir. I wasn't aware the new line was that literal.
Zeitounator avatar
fr flag
There's no problem with any new line, only with the name of the variable you are appending to.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.