Hi there,

I'm using ansible 1.9.2. We don't use ansible for configuration management, 
but instead for deployment automation.

I'm trying to set some conditions early on in a play so that the right 
tasks get executed under the right conditions later in the play. This play 
is called multiple times from a playbook. I thought I had a good thing 
going here, until I realized upon the 2nd include of the play, the default 
I intended for a var was set to a value which got set within the first 
include of the play. I had thought that upon the 2nd include of the play, 
all vars would get set again to my intended default value. But that didn't 
happen.

The details of what's happening, including the playbook and play are at the 
bottom...

And when you get there .. Is this expected? Is this a bug? Shouldn't it 
work the way I expect?

The reason why I'm even going down this road is because ansible doesn't 
support conditionally including a play within a playbook. "Conditions on 
include don't apply to the include itself, it is applied to the tasks 
included", from a previous post.

Thank you in advance!
kallen


ansible_1.9.2 $ cat sushi_playbook.yml
---
- hosts: 127.0.0.1
  connection: local
  gather_facts: False
  tasks:

# in group_vars/all:
# by default, verbose is False
# ... yes, the inventory has a group called 'all'

- include: "{{ playbook_dir }}/dev/test_sushi.yml fish=hamachi 
sushi_tool_prepare=true"
- include: "{{ playbook_dir }}/dev/test_sushi.yml fish=hamachi 
sushi_tool_phase_pickles=true"

#- include: "{{ playbook_dir }}/dev/test_sushi.yml fish=sake 
sushi_tool_prepare=true"
#- include: "{{ playbook_dir }}/dev/test_sushi.yml fish=sake 
sushi_tool_phase_pickles=true"


ansible_1.9.2 $ cat -b dev/test_sushi.yml
     1  ---
     2  - hosts: 127.0.0.1
     3    connection: local
     4    gather_facts: False
     5    vars:
     6      # set the defaults:
     7      testify: False
     8      sushi_tool_prepare: False
     9      sushi_tool_phase_pickles: False
    10      sushi_tool_phase_ginger: False
    11      sushi_tool_phase_daikon: False
    12      local_run_sushi_prepare_hamachi: False
    13      local_run_sushi_prepare_sake: False
    14      local_fish_is_hamachi: False
    15      local_fish_is_sake: False

    16    tasks:
    17    - name: start of play
    18      debug: msg=
"========================================================================================"

    19    - debug: var=fish
    20    # For these next 2 vars, i expect them to always be False here, 
having taken
    21    # on such value from vars default above ^^. But my expectation is 
thwarted
    22    - debug: var=local_run_sushi_prepare_sake
    23    - debug: var=local_run_sushi_prepare_hamachi

    24    - set_fact: testify=True
    25      when: verbose|bool

    26    - set_fact: sushi_phase="prepare"
    27      when: sushi_tool_prepare|bool
    28    - set_fact: sushi_phase="pickles"
    29      when: sushi_tool_phase_pickles|bool
    30    - set_fact: sushi_phase="ginger"
    31      when: sushi_tool_phase_ginger|bool
    32    - set_fact: sushi_phase="daikon"
    33      when: sushi_tool_phase_daikon|bool

    34    - set_fact: local_fish_is_hamachi=True
    35      when: fish == "hamachi"
    36    - set_fact: local_fish_is_sake=True
    37      when: fish == "sake"

    38    # TODO is this a bug? from the playbook, when this play is called 
a second
    39    # time, the default of False at the top isn't honored?
    40    - set_fact: local_run_sushi_prepare_hamachi=True
    41      when: local_fish_is_hamachi|bool and sushi_tool_prepare|bool
    42    - set_fact: local_run_sushi_prepare_sake=True
    43      when: local_fish_is_sake|bool and sushi_tool_prepare|bool

    44    - debug: var=sushi_tool_prepare
    45    - debug: var=sushi_phase
    46    - debug: var=local_run_sushi_prepare_sake
    47    - debug: var=local_run_sushi_prepare_hamachi
    48    - debug: var=local_run_upgradesushi_pm
    49    - debug: var=local_run_upgradedb_mt
    50    - debug: var=verbose
    51    - debug: var=testify



In the run output below, I expect variable local_run_sushi_prepare_hamachi 
to be False at line 23 in the play each and every time the play gets 
included from the playbook. But, it doesn't. sadface.


$ ansible-playbook -i inventory/on1.ini -e verbose=false sushi_playbook.yml

PLAY [127.0.0.1] 
**************************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.034)       0:00:00.034 
**********
===============================================================================

PLAY [127.0.0.1] 
**************************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.000)       0:00:00.035 
**********
===============================================================================

TASK: [start of play] 
*********************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.000)       0:00:00.035 
**********
ok: [127.0.0.1] => {
    "msg": 
"========================================================================================"
}

msg:
========================================================================================

TASK: [debug var=fish] 
********************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.011)       0:00:00.047 
**********
ok: [127.0.0.1] => {
    "var": {
        "fish": "hamachi"
    }
}

TASK: [debug var=local_run_sushi_prepare_sake] 
********************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.003)       0:00:00.051 
**********
ok: [127.0.0.1] => {
    "var": {
        "local_run_sushi_prepare_sake": "False"
    }
}

TASK: [debug var=local_run_sushi_prepare_hamachi] 
*****************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.003)       0:00:00.055 
**********
ok: [127.0.0.1] => {
    "var": {
        "local_run_sushi_prepare_hamachi": "False"
    }
}

TASK: [set_fact testify=True] 
*************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.003)       0:00:00.058 
**********
skipping: [127.0.0.1]

TASK: [set_fact sushi_phase="prepare"] 
****************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.004)       0:00:00.063 
**********
ok: [127.0.0.1]

TASK: [set_fact sushi_phase="pickles"] 
****************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.004)       0:00:00.067 
**********
skipping: [127.0.0.1]

TASK: [set_fact sushi_phase="ginger"] 
*****************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.005)       0:00:00.072 
**********
skipping: [127.0.0.1]

TASK: [set_fact sushi_phase="daikon"] 
*****************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.006)       0:00:00.078 
**********
skipping: [127.0.0.1]

TASK: [set_fact local_fish_is_hamachi=True] 
***********************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.005)       0:00:00.084 
**********
ok: [127.0.0.1]

TASK: [set_fact local_fish_is_sake=True] 
**************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.005)       0:00:00.089 
**********
skipping: [127.0.0.1]

TASK: [set_fact local_run_sushi_prepare_hamachi=True] 
*************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.005)       0:00:00.095 
**********
ok: [127.0.0.1]

TASK: [set_fact local_run_sushi_prepare_sake=True] 
****************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.004)       0:00:00.100 
**********
skipping: [127.0.0.1]

TASK: [debug var=sushi_tool_prepare] 
******************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.005)       0:00:00.106 
**********
ok: [127.0.0.1] => {
    "var": {
        "sushi_tool_prepare": "true"
    }
}

TASK: [debug var=sushi_phase] 
*************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.003)       0:00:00.109 
**********
ok: [127.0.0.1] => {
    "var": {
        "sushi_phase": "prepare"
    }
}

TASK: [debug var=local_run_sushi_prepare_sake] 
********************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.003)       0:00:00.113 
**********
ok: [127.0.0.1] => {
    "var": {
        "local_run_sushi_prepare_sake": "False"
    }
}

TASK: [debug var=local_run_sushi_prepare_hamachi] 
*****************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.003)       0:00:00.116 
**********
ok: [127.0.0.1] => {
    "var": {
        "local_run_sushi_prepare_hamachi": "True"
    }
}

TASK: [debug var=local_run_upgradesushi_pm] 
***********************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.003)       0:00:00.119 
**********
ok: [127.0.0.1] => {
    "var": {
        "local_run_upgradesushi_pm": "local_run_upgradesushi_pm"
    }
}

TASK: [debug var=local_run_upgradedb_mt] 
**************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.002)       0:00:00.122 
**********
ok: [127.0.0.1] => {
    "var": {
        "local_run_upgradedb_mt": "local_run_upgradedb_mt"
    }
}

TASK: [debug var=verbose] 
*****************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.002)       0:00:00.124 
**********
ok: [127.0.0.1] => {
    "var": {
        "verbose": "false"
    }
}

TASK: [debug var=testify] 
*****************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.004)       0:00:00.129 
**********
ok: [127.0.0.1] => {
    "var": {
        "testify": "False"
    }
}

PLAY [127.0.0.1] 
**************************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.006)       0:00:00.136 
**********
===============================================================================

TASK: [start of play] 
*********************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.000)       0:00:00.136 
**********
ok: [127.0.0.1] => {
    "msg": 
"========================================================================================"
}

msg:
========================================================================================

TASK: [debug var=fish] 
********************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.002)       0:00:00.138 
**********
ok: [127.0.0.1] => {
    "var": {
        "fish": "hamachi"
    }
}

TASK: [debug var=local_run_sushi_prepare_sake] 
********************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.004)       0:00:00.143 
**********
ok: [127.0.0.1] => {
    "var": {
        "local_run_sushi_prepare_sake": "False"
    }
}

TASK: [debug var=local_run_sushi_prepare_hamachi] 
*****************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.011)       0:00:00.154 
**********
ok: [127.0.0.1] => {
    "var": {
        "local_run_sushi_prepare_hamachi": "True"
    }
}

TASK: [set_fact testify=True] 
*************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.004)       0:00:00.158 
**********
skipping: [127.0.0.1]

TASK: [set_fact sushi_phase="prepare"] 
****************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.004)       0:00:00.163 
**********
skipping: [127.0.0.1]

TASK: [set_fact sushi_phase="pickles"] 
****************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.004)       0:00:00.167 
**********
ok: [127.0.0.1]

TASK: [set_fact sushi_phase="ginger"] 
*****************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.005)       0:00:00.172 
**********
skipping: [127.0.0.1]

TASK: [set_fact sushi_phase="daikon"] 
*****************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.004)       0:00:00.177 
**********
skipping: [127.0.0.1]

TASK: [set_fact local_fish_is_hamachi=True] 
***********************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.004)       0:00:00.181 
**********
ok: [127.0.0.1]

TASK: [set_fact local_fish_is_sake=True] 
**************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.004)       0:00:00.186 
**********
skipping: [127.0.0.1]

TASK: [set_fact local_run_sushi_prepare_hamachi=True] 
*************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.006)       0:00:00.192 
**********
skipping: [127.0.0.1]


TASK: [set_fact local_run_sushi_prepare_sake=True] 
****************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.004)       0:00:00.197 
**********
skipping: [127.0.0.1]

TASK: [debug var=sushi_tool_prepare] 
******************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.004)       0:00:00.201 
**********
ok: [127.0.0.1] => {
    "var": {
        "sushi_tool_prepare": "False"
    }
}

TASK: [debug var=sushi_phase] 
*************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.004)       0:00:00.205 
**********
ok: [127.0.0.1] => {
    "var": {
        "sushi_phase": "pickles"
    }
}

TASK: [debug var=local_run_sushi_prepare_sake] 
********************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.003)       0:00:00.209 
**********
ok: [127.0.0.1] => {
    "var": {
        "local_run_sushi_prepare_sake": "False"
    }
}

TASK: [debug var=local_run_sushi_prepare_hamachi] 
*****************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.002)       0:00:00.212 
**********
ok: [127.0.0.1] => {
    "var": {
        "local_run_sushi_prepare_hamachi": "True"
    }
}

TASK: [debug var=local_run_upgradesushi_pm] 
***********************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.002)       0:00:00.215 
**********
ok: [127.0.0.1] => {
    "var": {
        "local_run_upgradesushi_pm": "local_run_upgradesushi_pm"
    }
}

TASK: [debug var=local_run_upgradedb_mt] 
**************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.002)       0:00:00.218 
**********
ok: [127.0.0.1] => {
    "var": {
        "local_run_upgradedb_mt": "local_run_upgradedb_mt"
    }
}

TASK: [debug var=verbose] 
*****************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.002)       0:00:00.220 
**********
ok: [127.0.0.1] => {
    "var": {
        "verbose": "false"
    }
}

TASK: [debug var=testify] 
*****************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.003)       0:00:00.223 
**********
ok: [127.0.0.1] => {
    "var": {
        "testify": "False"
    }
}

PLAY RECAP 
********************************************************************
Tuesday 21 July 2015  16:55:12 -0700 (0:00:00.002)       0:00:00.226 
**********
===============================================================================
127.0.0.1                  : ok=29   changed=0    unreachable=0    failed=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 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/471e830a-fcba-41ad-a090-16c4d3724be5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to