If I understand your intent, it is to only update Apache if it is already
installed, so that systems without Apache on them won't accidentally have
it installed by mistake. A better way to go about this would be to have an
"apache" or "webserver" group, and assign that group only to the servers
that are supposed to have apache installed on them

You didn't post your inventory, but let's say it looks like this now:

---- start inventory -----
host1
host2
host3
host4
---- end inventory ----

Lets make it more descriptive:

---- start inventory ----
[webservers]
host1
host2

[databases]
host3

[proxy-servers]
host4
---- end inventory

you can now have a playbook like this:

---- start playbook ----
---
- hosts: all
  user: vagrant
  sudo: true
  tasks:
    - name: update apt
      apt: update_cache: yes

- hosts: webservers
  user: vagrant
  sudo: true
  tasks:
    - name: upgrade apache
      apt: name={{ item }} state=latest
      with_items:
        - apache2-mpm-worker
        - apache2.2-bin
        - apache2.2-common

---- end playbook ----

You can add sections for each type of system, and the other systems will
just skip the plays related to webservers and vice versa.  You can then add
handlers for apache so that apache gets restarted on update and another
play so that apache is started automatically..

The logical next step is then to move everything related to "webserver" in
a role (or roles) that is then called by the main playbook. Take a look at
the Best Practices document for more information on that:
http://docs.ansible.com/playbooks_best_practices.html


----
Mark McCoy <http://markmccoy.us>


On Wed, Oct 1, 2014 at 10:24 AM, Johan Chassaing <chassaing.jo...@gmail.com>
wrote:

> Hi,
>
> I run ansible 1.7.2 under ubuntu 14.04 amd64
>
> I made a playbook to upgrade only package that I added to a list.
> (
> https://github.com/johan-chassaing/linux/blob/master/ansible/playbook/package_upgrade_list.yml
> )
>
> So, I retrieve the list of every packages that need to be upgraded on my
> server, and it install the package when the result is matched with an entry
> of my list.
>
> For my test I got 4 package that could be upgraded: apache2-mpm-worker
> apache2.2-bin apache2.2-common bash
>
> If I do not insert the when condition, all packages are installed.
>
> TASK: [Upgrade]
> ***************************************************************
> <127.0.0.1> REMOTE_MODULE apt
> name=apache2-mpm-worker,apache2.2-bin,apache2.2-common,bash state=latest
> changed: [127.0.0.1] =>
> (item=apache2-mpm-worker,apache2.2-bin,apache2.2-common,bash) =>
> {"changed": true, "
>
> If I add the when condition, install is skipped.
>
> TASK: [Upgrade]
> ***************************************************************
> skipping: [127.0.0.1] =>
> (item=apache2-mpm-worker,apache2.2-bin,apache2.2-common)
> PLAY RECAP
> 127.0.0.1                  : ok=3    changed=1    unreachable=0    failed=0
>
> If I replace the APT module with a message, only bash package is skipped.
>
> TASK: [Upgrade]
> ***************************************************************
> <127.0.0.1> ESTABLISH CONNECTION FOR USER: vagrant
> ok: [127.0.0.1] => (item=apache2-mpm-worker) => {
>     "item": "apache2-mpm-worker",
>     "msg": "Package to update:apache2-mpm-worker"
> }
> <127.0.0.1> ESTABLISH CONNECTION FOR USER: vagrant
> ok: [127.0.0.1] => (item=apache2.2-bin) => {
>     "item": "apache2.2-bin",
>     "msg": "Package to update:apache2.2-bin"
> }
> <127.0.0.1> ESTABLISH CONNECTION FOR USER: vagrant
> ok: [127.0.0.1] => (item=apache2.2-common) => {
>     "item": "apache2.2-common",
>     "msg": "Package to update:apache2.2-common"
> }
> skipping: [127.0.0.1] => (item=bash)
>
> Do you have any information about that?
> Or any tips how I can debug?
> Thank you
>
> Johan
>
> --
> 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/e7463bd2-07ee-42db-b31e-9a06f73502ad%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/e7463bd2-07ee-42db-b31e-9a06f73502ad%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAP2%3DG9Ow3PdOSv3rd%3DrKd6ZbQKMKBK6Xb4tKNe_UqV4yLAQd5A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to