How to switch a user per task or set of tasks?

前端 未结 5 1879
無奈伤痛
無奈伤痛 2020-11-29 17:08

A recurring theme that\'s in my ansible playbooks is that I often must execute a command with sudo privileges (sudo: yes) because I\'d like to do it for a certa

5条回答
  •  北海茫月
    2020-11-29 17:38

    In Ansible >1.4 you can actually specify a remote user at the task level which should allow you to login as that user and execute that command without resorting to sudo. If you can't login as that user then the sudo_user solution will work too.

    ---
    - hosts: webservers
      remote_user: root
      tasks:
        - name: test connection
          ping:
          remote_user: yourname
    

    See http://docs.ansible.com/playbooks_intro.html#hosts-and-users

提交回复
热议问题