Hi, If it is skipping, the when clause is false. Couldn't understand why do you need this when clause and why you are trying to convert to 'int'... could you explain?
// Anderson 2017-04-14 7:41 GMT+01:00 acharya tejaswi indurthi < [email protected]>: > Hi > > I am trying to start the instances from a list of instances-ids using > with_items and when condition.I have created a databases with four columns > consisting of instance-ids,start-time,end-time and instance-name.Now by > using jinja2 templates in ansible i have assigned 4 columns into four > arrays.In the playbook i took present time and when this present time > equals to the start time in the databases then the instance ids that are > assigned to that start time get to be started.The error here is that i was > able to pass the instance-ids to ec2 modules but those getting skipped.Here > i took from myvar1 to myvar4 for 4 arrays as i mentioned above. myvar5 and > myvar6 for the start time and end time that is matching with present > time.And the playbook is > > --- > - hosts: localhost > connection: local > gather_facts: false > tasks: > - name: Retrieve stuff from mysql > command: mysql -e 'select * from instance_data' automation > register: results > - debug: var=results.stdout.split(\t) > > - name: date and time > command: date +"%H:%M" > register: date > > - set_fact: > myvar1: | > {% set list1 = results.stdout.split('\n') %} > {% set servername = [] %} > {% for j in list1 %} > {% set k= j.split('\t') %} > {% set ignored = servername.extend(k) %} > {% endfor %} > {% set list3= list1|length %} > {% set i= range(list3) %} > {% set u = i|max %} > {% set l = u+1 %} > {% for j in i %} > {% set a = (4*j) %} > {{servername[a]}} > {% endfor %} > > myvar2: | > {% set list1 = results.stdout.split('\n') %} > {% set servername = [] %} > {% for j in list1 %} > {% set k= j.split('\t') %} > {% set ignored = servername.extend(k) %} > {% endfor %} > {% set list3= list1|length %} > {% set i= range(list3) %} > {% set u = i|max %} > {% set l = u+1 %} > {% for j in i %} > {% set b = ((4*j)+1) %} > {{servername[b]}} > {% endfor %} > > myvar3: | > {% set list1 = results.stdout.split('\n') %} > {% set servername = [] %} > {% for j in list1 %} > {% set k= j.split('\t') %} > {% set ignored = servername.extend(k) %} > {% endfor %} > {% set list3= list1|length %} > {% set i= range(list3) %} > {% set u = i|max %} > {% set l = u+1 %} > {% for j in i %} > {% set c = ((4*j)+2) %} > {{servername[c]}} > {% endfor %} > > myvar4: | > {% set list1 = results.stdout.split('\n') %} > {% set servername = [] %} > {% for j in list1 %} > {% set k= j.split('\t') %} > {% set ignored = servername.extend(k) %} > {% endfor %} > {% set list3= list1|length %} > {% set i= range(list3) %} > {% for j in i %} > {% set d = ((4*j)+3) %} > {{servername[d]}} > {% endfor %} > > myvar5: | > {% set list1 = results.stdout.split('\n') %} > {% set servername = [] %} > {% for j in list1 %} > {% set k= j.split('\t') %} > {% set ignored = servername.extend(k) %} > {% endfor %} > {% set list3= list1|length %} > {% set i= range(list3) %} > {% set t = date.stdout %} > {% for m in i %} > {% set e = ((4*m)+1) %} > {% set w = (4*m) %} > {% if t is defined and t == servername[e]%} > {% set w = (4*m) %} > {{servername[w]}} > {% endif %} > {% endfor %} > > myvar6: | > {% set list1 = results.stdout.split('\n') %} > {% set servername = [] %} > {% for j in list1 %} > {% set k= j.split('\t') %} > {% set ignored = servername.extend(k) %} > {% endfor %} > {% set list3= list1|length %} > {% set i= range(list3) %} > {% set t = date.stdout %} > {% for n in i %} > {% set f = ((4*n)+2) %} > {% if t is defined and t == servername[f]%} > {% set z = (4*n) %} > {% endif %} > {% endfor %} > > - debug: var=myvar1.split(\n) > - debug: var=myvar2.split(\n) > - debug: var=myvar3.split(\n) > - debug: var=myvar4.split(\n) > - debug: var=myvar5.split(\n) > - debug: var=myvar6.split(\n) > - debug: var=date.stdout > > - name: Start myserver instance > local_action: > module: ec2 > region: "us-east-1" > instance_ids: "{{myvar5.split(\n)}}" > state: running > with_items: "{{myvar5.split(\n)}}" > when: "item|int" > > Output: > > PLAY [localhost] ****************************** > ********************************* > > TASK [Retrieve stuff from mysql] ****************************** > ***************** > changed: [localhost] > > TASK [debug] ************************************************************ > ******* > ok: [localhost] => { > "results.stdout.split(\t)": [ > "instance_id", > "start_time", > "stop_time", > "instance_name", > "i-00440942b2bacbd03", > "17:09", > "16:00", > "Billing", > "i-00ef49e66588585ef", > "17:09", > "16:00", > "ansible-launched", > "i-01543b3b959fe0eca", > "09:00", > "20:32", > "windows-ec2-telegraf", > "i-0336017296fcf14ca", > "16:41", > "20:32", > "openvpn", > "i-07d1b8b92a90f8498", > "11:00", > "20:00", > "ec2-private-inst2", > "i-08f713f2803c4f1c2", > "21:49", > "15:21", > "ec2-private", > "i-0a3910522c326d26b", > "20:12", > "14:55", > "Automation2", > "i-0ebb9a1517bfe54d4", > "11:46", > "14:55", > "Bonding" > ] > } > > TASK [date and time] ****************************** > ***************************** > changed: [localhost] > > TASK [set_fact] ****************************** > ********************************** > ok: [localhost] > > TASK [debug] ************************************************************ > ******* > ok: [localhost] => { > "myvar1.split(\n)": [ > "instance_id", > "i-00440942b2bacbd03", > "i-00ef49e66588585ef", > "i-01543b3b959fe0eca", > "i-0336017296fcf14ca", > "i-07d1b8b92a90f8498", > "i-08f713f2803c4f1c2", > "i-0a3910522c326d26b", > "i-0ebb9a1517bfe54d4" > ] > } > > TASK [debug] ************************************************************ > ******* > ok: [localhost] => { > "myvar2.split(\n)": [ > "start_time", > "17:09", > "17:09", > "09:00", > "16:41", > "11:00", > "21:49", > "20:12", > "11:46" > ] > } > > TASK [debug] ************************************************************ > ******* > ok: [localhost] => { > "myvar3.split(\n)": [ > "stop_time", > "16:00", > "16:00", > "20:32", > "20:32", > "20:00", > "15:21", > "14:55", > "14:55" > ] > } > > TASK [debug] ************************************************************ > ******* > ok: [localhost] => { > "myvar4.split(\n)": [ > "instance_name", > "Billing", > "ansible-launched", > "windows-ec2-telegraf", > "openvpn", > "ec2-private-inst2", > "ec2-private", > "Automation2", > "Bonding" > ] > } > > TASK [debug] ************************************************************ > ******* > ok: [localhost] => { > "myvar5.split(\n)": [ > "i-0ebb9a1517bfe54d4" > ] > } > > TASK [debug] ************************************************************ > ******* > ok: [localhost] => { > "myvar6.split(\n)": [] > } > > TASK [debug] ************************************************************ > ******* > ok: [localhost] => { > "date.stdout": "11:46" > } > > TASK [Start myserver instance] ****************************** > ******************* > skipping: [localhost] => (item=i-0ebb9a1517bfe54d4) > > PLAY RECAP ************************************************************ > ********* > localhost : ok=11 changed=2 unreachable=0 > failed=0 > > > Thanks, > > > > -- > 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/7308e464-e250-4706-bcce-9c985c2b45d9%40googlegroups. > com > <https://groups.google.com/d/msgid/ansible-project/7308e464-e250-4706-bcce-9c985c2b45d9%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 [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/CAFfkfk-RSb6dWzwhoOBXvpNWX2e6o5ZUu4bqiEPU-wS14-FGyg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
