Math Ansible sum int value转换为注册值

Math Ansible sum int value转换为注册值,math,ansible,sum,Math,Ansible,Sum,我需要用ansible将一个整数和一个注册值相加。。我试过这个,但不起作用--> 但我得到--> 提前谢谢 我认为问题在于uid和gid变量在set\u fact任务完成之前不可用。如果您拆分set\u fact任务,它应该可以工作。如下所示: -设置事实: uid:“{lastuser.stdout.split(':')[2]}” gid:“{lastuser.stdout.split(':')[3]}” -设定事实: newuid:{uid|int+5}} newgid:{{gid|int+

我需要用ansible将一个整数和一个注册值相加。。我试过这个,但不起作用-->

但我得到-->


提前谢谢

我认为问题在于
uid
gid
变量在
set\u fact
任务完成之前不可用。如果您拆分
set\u fact
任务,它应该可以工作。如下所示:

-设置事实:
uid:“{lastuser.stdout.split(':')[2]}”
gid:“{lastuser.stdout.split(':')[3]}”
-设定事实:
newuid:{uid|int+5}}
newgid:{{gid|int+5}}”
-调试:
味精:
-“UID为{UID}}GID为{GID}”
-“新UID为{newuid}}GID为{{newgid}”
---
- hosts: localhost
  gather_facts: false
  tasks:
    - name: Ricavo ultima linea /etc/passwd
      shell: tail -1 /etc/passwd
      register: lastuser
      ignore_errors: no

    - set_fact:
        uid: "{{ lastuser.stdout.split(':')[2] }}"
        gid: "{{ lastuser.stdout.split(':')[3] }}"
        newuid: "{{ uid|int + 5 }}"
        newgid: "{{ gid|int + 5 }}"
    - debug:
        msg: "UID is {{ uid }} GID is {{ gid }}"
    - debug:
        msg: "NEW UID is {{ newuid }} GID is {{ newgid }}"
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'uid' is undefined\n\nThe error appears to have been in '/tmp/test_ansible/get_lastuser.yaml': line 10, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n    - set_fact:\n      ^ here\n"}