On 5/5/20 12:26 PM, Meir Yanovich wrote:
> i have this ansible simple playbook :
> where "/home/ec2-user/test1.txt" exists on disk
>
>
> |
> ---
> -name:check ifexsist
> hosts:localhost
> gather_facts:false
> tasks:
>
> -name:Getproject name
> shell:"echo 'hhhhhhhh'"
> register:name_var
>
>
> -name:Checkifthetest.log exists inpath
> stat:
> path:"/home/ec2-user/test1.txt1"
> register:log_result_1
>
> -name:CheckifTheTest.log exists inp_home
> stat:
> path:"/home/ec2-user/test1.txt"
> register:log_result_2
> when:name_var.stdout ismatch("hhhhhhhh")
>
> -set_fact:
> my_result:"{{ log_result_1.stat.exists or (log_result_2 is not skipped and log_result_2.stat.exists) }}"
>
> -debug:
> msg:"#################################### result_value ######################################"
> -debug:
> var:my_result
>
>
> -name:Createtemporary log folder
> file:
> path:"/home/ec2-user/log_tmp"
> state:directory
> when:my_result.stat.exists
>
> |
>
>
>
>
>
>
> I expect that the my_result will have the value of the right register in this case log_result_2
No the output is a boolean, variables are evaluated in your expression.
Regards
Racke
>
> but I'm getting this error:
>
>
> |
> ansible-playbook 2.9.7
> config file =/etc/ansible/ansible.cfg
> configured modulesearch path =['/home/ec2-user/.ansible/plugins/modules','/usr/share/ansible/plugins/modules']
> ansible python modulelocation =/home/ec2-user/venv_ansible_new/lib64/python3.7/site-packages/ansible
> executable location =/home/ec2-user/venv_ansible_new/bin/ansible-playbook
> python version =3.7.6(default,Feb262020,20:54:15)[GCC 7.3.120180712(RedHat7.3.1-6)]
> Using/etc/ansible/ansible.cfg asconfig file
> [WARNING]:Noinventory was parsed,only implicitlocalhost isavailable
> [WARNING]:provided hosts list isempty,only localhost isavailable.Notethat the implicitlocalhost does notmatch 'all'
>
> PLAYBOOK:test3.yml
> *************************************************************************************************************************************************************************************************************************
> 1plays intest3.yml
>
> PLAY [check
> ifexsist]**********************************************************************************************************************************************************************************************************************
> META:ran handlers
>
> TASK [Getproject
> name]*********************************************************************************************************************************************************************************************************************
> task path:/home/ec2-user/test3.yml:7
> Tuesday05May2020 09:56:22+0000(0:00:00.070) 0:00:00.070***********
> changed:[localhost]=>changed=true
> cmd:echo 'hhhhhhhh'
> delta:'0:00:00.002594'
> end:'2020-05-05 09:56:22.684370'
> rc:0
> start:'2020-05-05 09:56:22.681776'
> stderr:''
> stderr_lines:<omitted>
> stdout:hhhhhhhh
> stdout_lines:<omitted>
>
> TASK [Checkifthetest.log exists
> inpath]**************************************************************************************************************************************************************************************************
> task path:/home/ec2-user/test3.yml:12
> Tuesday05May2020 09:56:22+0000(0:00:00.256) 0:00:00.327***********
> ok:[localhost]=>changed=false
> stat:
> exists:false
>
> TASK [CheckifTheTest.log exists
> inp_home]************************************************************************************************************************************************************************************************
> TASK [Createtemporary log
> folder]**********************************************************************************************************************************************************************************************************
> task path:/home/ec2-user/test3.yml:32
> Tuesday05May2020 09:56:23+0000(0:00:00.010) 0:00:00.819***********
> fatal:[localhost]:FAILED!=>
> msg:|-
> Theconditional check 'my_result.stat.exists'failed.Theerror was:error whileevaluating conditional
> (my_result.stat.exists):'bool object'has noattribute 'stat'
>
> Theerror appears to be in'/home/ec2-user/test3.yml':line 32,column 7,but may
> be elsewhere inthe file depending on the exact syntax problem.
>
> Theoffending line appears to be:
>
>
> -name:Createtemporary log folder
> ^here
>
> |
>
>
> --
> 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-proje...@googlegroups.com <mailto:
ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/ansible-project/11ca92bf-0a19-486a-abac-875e5589bd21%40googlegroups.com
> <
https://groups.google.com/d/msgid/ansible-project/11ca92bf-0a19-486a-abac-875e5589bd21%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.