Whatever "vars" is, it doesn't have any data with that name -          
exactly...  it will be a new file to be created by the copy's "dest ."


compare_out.stdout is having   the output of hundreds of lines to be 
printed parallely .  I have disabled the printing of its output (to reduce 
screen space) by 
register: compare_out
no_log: true 

#######
Perhaps you mean this:

  dest="{{ comp_file }}"

Whatever. In any case, if I were you, I'd throw in a debug step and print 
out the values of "compare_out.stdout" and, er, whatever you think "dest" 
is supposed to be ("vars"? but I think you just mean "comp_file").
### #######
 on the above ,  I am trying to write the compare_out.stdout  which is 100+ 
lines  to a file which  have to created by  calling the variable "{{ 
comp_file }}"  as dest using copy .


may be we need template? Jinja ?  
Learn to study more ..  :-)



On Friday, November 11, 2022 at 1:34:15 AM UTC+5:30 [email protected] wrote:

> Wait a second. You're saying "{{ vars[ comp_file ] }}", but
>
>   
> comp_file="/home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt"
>
> So you're trying to pull a value from the "vars" dict with the key of
>   "
> /home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt
> ".
>
> Whatever "vars" is, it doesn't have any data with that name.
>
> Perhaps you mean this:
>
>   dest="{{ comp_file }}"
>
> Whatever. In any case, if I were you, I'd throw in a debug step and print 
> out the values of "compare_out.stdout" and, er, whatever you think "dest" 
> is supposed to be ("vars"? but I think you just mean "comp_file").
>
>
> On 11/10/22 1:26 PM, Veera wrote:
>
>
> Thanks for pointing  as i did notice that , and I have corrected the  
> three left braces on "exec_date". 
>
> Second, mustaches (i.e. "{{" … "}}") never nest  <<  Yes , I tried earlier 
> that and even now after reverting back , still the same issue .. 
> Execution error for the play below.
>
> fatal: [server1 -> localhost]: FAILED! => {"msg": "The task includes an 
> option with an undefined variable. The error was: 'dict object' has no 
> attribute 
> u'/home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt'\n\nThe
>  
> error appears to be in 
> '/home/unixops/ansible/linux_patching/compare_sanity.yml': line 7, column 
> 3, but may\nbe elsewhere in the file depending on the exact syntax 
> problem.\n\nThe offending line appears to be:\n\n\n- name: create compare 
> file using precheck and postcheck sanity checks\n  ^ here\n"}
>
>
> On Thursday, November 10, 2022 at 10:24:51 PM UTC+5:30 [email protected] 
> wrote:
>
>> A couple of things. First,
>>
>> comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
>> exec_date }}.txt
>>
>> has three left braces on "exec_date".
>>
>> Second, mustaches (i.e. "{{" … "}}") never nest. So
>>
>>     copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
>> }} ] }}"
>>
>> should be
>>
>>     copy   content="{{ compare_out.stdout }}" dest="{{ vars[ comp_file ] 
>> }}"
>>
>> Well, at least that's "dest=" without nested mustaches. Whether it's 
>> right or not I don't know, but it's less wrong this way.
>>
>>
>> On 11/10/22 9:16 AM, Veera wrote:
>>
>> Hi, 
>>
>> I am trying to copy the  contents from a register output  to a file  in 
>> the local server.
>> However , I have challenges in re-calling the variable filename in the 
>> copy command.
>>
>> Correct me what I am missing. in dest="{{ vars[ {{ comp_file }} ] }}"  or 
>> "{{ compare_out.stdout }}"  in the last lines ..
>>
>>
>> [vee@server]$ grep comp_file  vars/postcheck_vars.yml
>> comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
>> exec_date }}.txt
>>
>> [vee@server]$ cat  compare_sanity.yml
>> - name: comparing file1 and file2 
>>   local_action: command /usr/bin/sdiff "{{ logs_dir }}"{{ 
>> inventory_hostname }}-Pre-{{ exec_date }}.txt   "{{ logs_dir }}"{{ 
>> inventory_hostname }}-Post-{{ exec_date }}.txt
>>   register: compare_out
>>   ignore_errors: yes
>>   no_log: True
>>
>> - name: create output  file
>>   local_action:
>>     copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
>> }} ] }}"
>>   [vee@server]$
>>
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ce5a217b-b8b5-456a-9a86-f27bcac9ba2en%40googlegroups.com.

Reply via email to