Ansible register捕获命令输出
在playbook中可以使用register将捕获命令的输出保存在临时变量中,然后使用debug模块进行显示输出。
--- - name: var user hosts: dev vars: user: yaoyao tasks: - name: create var user user: name: "{{ user }}" state: present register: create_user - debug: var: create_user ~ [student@workstation ~]$ ansible-playbook var_user.yaml PLAY [var user] ************************************************************************************************ TASK [Gathering Facts] ***************************************************************************************** ok: [servera.lab.example.com] TASK [create var user] ***************************************************************************************** ok: [servera.lab.example.com] TASK [debug] *************************************************************************************************** ok: [servera.lab.example.com] => { "create_user": { "append": false, "changed": false, "comment": "", "failed": false, "group": 1002, "home": "/home/yaoyao", "move_home": false, "name": "yaoyao", "shell": "/bin/bash", "state": "present", "uid": 1002 } } PLAY RECAP ***************************************************************************************************** servera.lab.example.com : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0