Some tasks in ansible are't executed

31 views
Skip to first unread message

Roman Dryndik

unread,
Jun 26, 2014, 7:59:14 AM6/26/14
to ansible...@googlegroups.com, rman-d...@rambler.ru

I'm using ansible for some deployment issues.

I want to do the following:

1. Install virtualenv
2. Activate installed virtual environment
3. Check if I'm in virtual environment

For this purposes I have the following playbook:

    ---
    - hosts: servers
        
      tasks:
        - name: update repository
          apt: update_cache=yes
          sudo: true
    
      tasks:
        - name: install git
          apt: name=git state=latest
          sudo: true
    
      tasks:
        - name: install pip
          apt: name=python-pip state=latest
          sudo: true
    
      tasks:
        - name: installing postgres
          sudo: true
          apt: name=postgresql state=latest
    
      tasks:
        - name: installing libpd-dev
          sudo: true
          apt: name=libpq-dev state=latest
    
      tasks:
        - name: installing psycopg
          sudo: true
          apt: name=python-psycopg2 state=latest
    
      tasks:
        - name: configuration of virtual env
          sudo: true
          pip: name=virtualenvwrapper state=latest
    
      tasks:
        - name: create virtualenv
          command: virtualenv venv
    
      tasks:
        - name: virtualenv activate
          shell: . ~/venv/bin/activate
    
      tasks:
        - name: "Guard code, so we are more certain we are in a virtualenv"
          shell: echo $VIRTUAL_ENV
          register: command_result
          failed_when: command_result.stdout == ""

The problem is that sometimes some tasks are not executed, but they have to... For instance in my case the task:

      tasks:
        - name: create virtualenv
          command: virtualenv venv

Is not executed.

But if I will comment 2 last tasks:

      tasks:
        - name: virtualenv activate
          shell: . ~/venv/bin/activate
    
      tasks:
        - name: "Guard code, so we are more certain we are in a virtualenv"
          shell: echo $VIRTUAL_ENV
          register: command_result
          failed_when: command_result.stdout == ""

The previous one works...

Can't get what I'm doing wrong. Can somebody hint me?

Michael DeHaan

unread,
Jun 26, 2014, 9:23:31 AM6/26/14
to ansible...@googlegroups.com, rman-d...@rambler.ru
You don't put the "tasks:" category in a playbook more than once.

This is a hash data structure, so you are basically clobbering it with another, again and again.

Just let the value of "tasks:" be a YAML list, and only put tasks in there once.


--
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.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e447bd97-72ce-425d-ac7f-512ded00c5d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages