I tried adding "changed_when" for when sel_out is not defined, but it gives 
me an error, so I am not sure how to use "changed_when" in this case. 
 What's the correct usage?

     - name: Check for ECC's
       shell: ipmitool sel list | grep -i ecc
       register: sel_out
       changed_when: sel_out is not defined
       async: 3
       poll: 2

fatal: [192.168.100.11]: FAILED! => {"ansible_job_id": 
"186470565638.100676", "changed": false, "cmd": "ipmitool sel list | grep 
-i ecc", "delta": "0:00:00.094723", "end": "2017-08-12 01:40:04.893313", 
"failed": true, "finished": 1, "rc": 1, "start": "2017-08-12 
01:40:04.798590", "stderr": "", "stderr_lines": [], "stdout": "", 
"stdout_lines": []}


I was able to use this method, which seems to work.  Is this the correct 
usage of "|| true"?

     - name: Check for ECC's
       shell: ipmitool sel list | grep -i ecc || true
       register: sel_out
       async: 3
       poll: 2


With the above usage, I am back to my original question.  How can I add 
conditionals to individual items in a debug msg list?  For instance, how 
can I add a conditional only for "{{sel_out.stdout.split('\n') }}"?  If i 
put the "when" in the same column as "name" and "debug" as Dick suggested, 
then it will impact the full debug msg list, not only the sel_out line.

     - name: Print results
       debug:
        msg:
           - "Board: {{ ansible_product_name }}"
           - "CPU: {{ ansible_processor[1] }}   Cores: {{ 
ansible_processor_cores }}   CPU Count: {{ ansible_processor_count }}"
           - "Memory: {{ ansible_memtotal_mb }}"
           - "ansible processor count: {{ ansible_processor_count }}"
           - "Log File: {{ logfile }}"
           - "{{ out.stdout.split('\n') }}"
           - "{{sel_out.stdout.split('\n') }}"



On Friday, August 11, 2017 at 2:51:29 AM UTC-7, Kai Stian Olstad wrote:
>
> On 11. aug. 2017 08:25, Ryan wrote: 
> > 
> > Sorry, I will attache the error next time. 
>
> But you didn't include all relevant output. 
>
>
> > I tried indenting it to the same column as name and debug, but it still 
> > failed.  If I change the command to something that returns a value for 
> > sel_out, the debug msg returns the expected output.  The error only 
> comes 
> > when sel_out is not defined. 
> > 
> > - name: Print results 
> >         debug: 
> >           msg: 
> >             - "Board: {{ ansible_product_name }}" 
> >             - "CPU: {{ ansible_processor[1] }}   Cores: {{ 
> > ansible_processor_cores }}   CPU Count: {{ ansible_processor_count }}" 
> >             - "Memory: {{ ansible_memtotal_mb }}" 
> >             - "ansible processor count: {{ ansible_processor_count }}" 
> >             - "Log File: {{ logfile }}" 
> >             - "{{ out.stdout.split('\n') }}" 
> >             - "{{sel_out.stdout.split('\n') }}" 
> >         when: sel_out is defined 
> > 
> > 
> > fatal: [192.168.100.11]: FAILED! => {"ansible_job_id": 
> > "717909993947.50020", "changed": true, "cmd": "ipmitool sel list | grep 
> -i 
> > ecc", "delta": "0:00:00.088089", "end": "2017-08-11 06:02:57.289040", 
> > "failed": true, "finished": 1, "rc": 1, "start": "2017-08-11 
> > 06:02:57.200951", "stderr": "", "stderr_lines": [], "stdout": "", 
> > "stdout_lines": []} > 
>
> This error has noting to do with you debug task, it's the task you 
> running "ipmitool sel list" 
> Had you included more information about this error you would have seen 
> that easy a few lines before this statement. 
>
> grep isn't finding any ecc in the output av return code 1, this means 
> failure to ansible. 
> To change this you have can add "changed_when" to the task. 
>
>
> -- 
> Kai Stian Olstad 
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fca35767-8f48-45a9-a251-624dd07ea7df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to