How to add become password in a task?

21 views
Skip to first unread message

ZillaYT

unread,
Nov 15, 2017, 8:27:20 AM11/15/17
to Ansible Project
I've read the docs and it seems like all of them point me to coding the p/w either on the CLI or in group vars, but I want to do this

---
- hosts: server
  gather_facts: no

  tasks:
  - name: Create a file in the server /etc file system
    file:
      path: /etc/test.txt
      state: touch
    become: yes
    become_password: mySecretpw # this does NOT work, what should?



Kai Stian Olstad

unread,
Nov 15, 2017, 9:21:29 AM11/15/17
to ansible...@googlegroups.com
What works is in the documentation.
The reason you don't find something like this in the documentation is because the feature doesn't exist.

--
Kai Stian Olstad

Jordan Borean

unread,
Nov 15, 2017, 2:12:52 PM11/15/17
to Ansible Project
This can still be done, you can set the ansible_become_password variable using the vars argument like so;

- command: whoami
become: yes
become_user: user
vars:
ansible_become_password: password

The vars key can be used to set any variable for that particular task and it can even include ansible_become_user if you want to override the host variable if set where become_user is just a fallback.

Thanks

Jordan

Reply all
Reply to author
Forward
0 new messages