store the output of math operator

42 views
Skip to first unread message

bablu

unread,
Feb 14, 2017, 7:30:13 AM2/14/17
to Ansible Project

   - name: Set the output of the this state
     set_fact: A="{{image_avl.stdout}}"          -- this is coming from the previous registered output
     tags: avl1

   - name: Define our static value for the desired image number
     set_fact: B={{retain}}                       -- this is coming from the inventory 
     tags: num2

   - name: difference
     set_fact: C = {{A}} - {{B}}  
     tags: del1


I want to store the value of A -B in C. However, its not storing and showing blank result 

DHAVAL JAISWAL

unread,
Feb 14, 2017, 10:12:43 AM2/14/17
to ansible...@googlegroups.com
solved it.


--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/keIYWBBA1c8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@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/0733469a-2cf8-48c1-8007-b6efb7ebbd63%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Dick Visser

unread,
Feb 14, 2017, 10:29:19 AM2/14/17
to ansible...@googlegroups.com
On 14 February 2017 at 16:12, DHAVAL JAISWAL <dhav...@gmail.com> wrote:
> solved it.

Well done!

Any chance of sharing *how* you solved it?


Thanks,

--
Dick Visser
Sr. System & Network Engineer
GÉANT

Want to join us? We're hiring: https://www.geant.org/jobs

DHAVAL JAISWAL

unread,
Feb 14, 2017, 11:28:38 AM2/14/17
to ansible...@googlegroups.com
 - name: Set the output of the this state
     set_fact: A="{{image_avl.stdout}}"          -- this is coming from the previous registered output
     tags: avl1

   - name: Define our static value for the desired image number
     set_fact: B={{retain}}                       -- this is coming from the inventory
     tags: num2

   - name: difference
     shell: C=`expr "{{image_avl.stdout}}" - {{retain}}`
     register: num_del 
     tags: del1
   - debug: var="num_del"

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/keIYWBBA1c8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Thanks & Regards
Dhaval Jaiswal

Nehal J Wani

unread,
Feb 15, 2017, 7:30:23 AM2/15/17
to ansible...@googlegroups.com, dhav...@gmail.com, dick....@geant.org
Invoking the shell module is not necessary. One can use jinja2. An example:

$ cat a.yaml
- hosts: localhost

tasks:
- set_fact: A="5"
- set_fact: B="6"
- set_fact: C="{{ A|int - B|int }}"
- debug: var=C

$ ansible-playbook -v a.yaml
No config file found; using defaults
[WARNING]: Host file not found: /etc/ansible/hosts

[WARNING]: provided hosts list is empty, only localhost is available


PLAY [localhost]
****************************************************************************************************************************************************************************

TASK [Gathering Facts]
**********************************************************************************************************************************************************************
ok: [localhost]

TASK [set_fact]
*****************************************************************************************************************************************************************************
ok: [localhost] => {"ansible_facts": {"A": "5"}, "changed": false}

TASK [set_fact]
*****************************************************************************************************************************************************************************
ok: [localhost] => {"ansible_facts": {"B": "6"}, "changed": false}

TASK [set_fact]
*****************************************************************************************************************************************************************************
ok: [localhost] => {"ansible_facts": {"C": "-1"}, "changed": false}

TASK [debug] ********************************************************************************************************************************************************************************
ok: [localhost] => {
"C": "-1",
"changed": false
}

PLAY RECAP **********************************************************************************************************************************************************************************
localhost : ok=5 changed=0 unreachable=0 failed=0
>> 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/CAL8fbwNOB9bkDrzDzOcBCKTY6EbbrfMxWwzHLCD2zpm_w6KfxQ%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
> --
> Thanks & Regards
> Dhaval Jaiswal
>
> --
> 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/CAH5ShBh4xinpsAxXdibrpL7c_OV5i9XE_jzEB4A%2BwumZ0W%2BZrw%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Nehal J Wani

Andy Magana

unread,
Apr 29, 2019, 5:57:36 PM4/29/19
to Ansible Project
Hello from Oklahoma City,

My name is Andreas I noticed your post looking around for something about subtracting two variables but my vars are dates converted to strings but I can't seem to get the two vars to subtract I started with a bash script.

#!/bin/bash
# TO PRINT THE NUMBER OF DAYS SINCE LAST AV UPDATE
past_date
=$(du -h --time testdate | grep -Eo '[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}')


# Perform a subtraction of past_date string
# from today's string divided by seconds times 12 hour days  
diff
=$((($(date +%s)-$(date +%s --date "$past_date"))/(3600*24)))
echo
It has been $diff days since the last AV DAT update



Any advice would be great.

Andreas Magana
Oklahoma City, OK
To unsubscribe from this group and all its topics, send an email to ansible...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages