STEPS TO REPRODUCE:
Here's my first try:
myMainPlay.yml
testInclude.yml
tasks:
The resulting error --> "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'ticket_number' is undefined\n\nThe error appears to have been in '/mydirectory/testInclude.yml': line 8, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: checking via debug\n ^ here\n"
Note that the main play was able to create the directory with the ticket_number passed in.
Next, I tried the following changes but with the same error --
[myMainPlay.yml] - include: testInclude.yml number="{{ ticket_number }}"
[testInclude.yml] msg: "the value of number is {{ number }}"
Based on this link --> (http://stackoverflow.com/questions/26784185/ansible-passing-evaluated-variables-to-includes) --> the first one should have worked without having to pass the variable explicitly in the include statement. Anyway, I tried explicitly passing variables in the include statement as shown above but it didn't work. It only worked when I passed something like number=1234567, and testInclude.yml was able to pick it up.
We believe the ticket you have filed is being somewhat misunderstood, as one thing works a little differently than stated.
Play vars are not shared across plays, even when one of them is included, only hostvars are available across plays.
************
So it looks like I misunderstood the Ansible document ("Using either syntax, variables passed in can then be used in the included files.") For now, I added "--extra-vars ticket_number=1234567" to the command line. However, I'd like to keep the command line invocation of ansible-playbook as short as possible.
Does anyone have any ideas/suggestions how I can pass in a user inputed value into an included playbook?
Thanks.