The pip module is smart- it shouldn't re-run the installation if the 
requested packages are already there. So you shouldn't need the extra task 
that checks first at all.

If for some reason you still want to do it this way, the reason your 
conditional is failing is because you're running the previous item in a 
loop using with_items- the registered result variable looks different (as 
it contains the results from each loop iteration). See 
http://docs.ansible.com/playbooks_loops.html#using-register-with-a-loop for 
details.

To get the behavior you want, you need to find the appropriate result in 
the list and conditionally run the pip module based on its return code. 
Since you're using the same items in both lists, and Ansible keeps the 
original items correlated with the results, might I suggest:

- name: pip install {{ item }}
  pip: requirements=/packages/{{ item.item }}/requirements.txt # this uses 
the "item" value that got stored alongside the result from your first task
  sudo_user: deploy
  with_items: python_result.results # this loops over the registered 
results from your first task
  when: item.rc == 1 # this uses the correlated stored return code from 
your first task

- Matt 

On Wednesday, April 29, 2015 at 8:06:33 AM UTC-7, Nicolas G wrote:
>
> Hi, I have a plabyook that checks if my python app has been installed and 
> only run pip install if the packages have not been installed.
>
> Unfortunately because I'm doing a check using with_items the register 
> value is a dictionary causing an error on the next when: statement when 
> evaluating the conditional..
>
> # CODE:
>
> - name: check if {{ item }} have been previously installed
>   shell: python -c "import {{ item }}"
>   register: python_result
>   ignore_errors: True
>   with_items:
>     - app1
>     - app2
>
> - name: pip install {{ item }}
>   pip: requirements=/packages/{{ item }}/requirements.txt
>   sudo_user: deploy
>   with_items:
>     - app1
>     - app2
>   when: python_result.rc == 1
>
>
> # Error output running with full verbosity (-vvvvvvv) :
>
> TASK: [pip install {{ item }}] *****************************************
> fatal: [server.example.co] => error while evaluating conditional: 
> python_result.rc == 1
>
>
> Any help please ? 
>
> Regards,
> N.
>

-- 
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/e1cfa327-b6b5-4ef6-ba2f-f4d0f0de0e83%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to