Hi,

example from previous reply will do all stages for you:

- name: Ensure packages are installed and the latest available version
  yum: name="{{ item }}" state=latest
  with_items:
    - some_package
    - some_other_package
    - a_third_package

This will check package presence, then install it if it is not installed 
and update if it is. This is the key: "state=latest"

On Tuesday, December 15, 2015 at 11:14:17 AM UTC-5, 张斌 wrote:
>
>  
> Thanks Calum.   I already went through the docs, and googled. I know how 
> to loop with items and install with yum.
>
> But i want to a list of RPMs to be check and install/upgrade, not sure if 
> there is a way to do so.
>
> how to loop with_items: for the three steps ? Perhaps something like the 
> following
>
> with_items: {{items}}
>
> - name: Check if Package is installed
>   command: rpm -q {{item}}
>   register: rpm_check
>   failed_when: rpm_check.rc > 1
>   changed_when: no
>
> - name: Install Package only if not installed
>   yum: name={{item}} state=present
>   when: rpm_check.rc == 1
>   
> - name: Update Package only if installed
>   yum: name={{item}} state=latest  update_cache=yes
>   when: rpm_check.rc == 0
>

-- 
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/96805cf2-1e4b-481e-af96-ca3138eb49e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to