ZhangZhihui's Blog  
---
- hosts: zubt1

  tasks:
    - name: Get current user
      shell: whoami
      register: current_user_nobecome

    - name: Get current user with become is true
      shell: whoami
      register: current_user_become
      become: true

    - name: Print current user
      debug:
         msg: Current user is "{{ current_user_nobecome.stdout }}". Current user with become true is "{{ current_user_become.stdout }}".

TASK [Print current user] *******************************************************************************************************************************************
ok: [zubt1] => {
    "msg": "Current user is \"scnzzh\". Current user with become true is \"root\"."
}

 

posted on 2020-12-14 11:59  ZhangZhihuiAAA  阅读(187)  评论(0编辑  收藏  举报