ansible - template task: write to root owned directory -


i want copy template generated file /etc/init.d folder. template task doesn't seem support sudo parameter. recommended way handle this? should copy temporary directory , move file with sudo?

the playbook task looks shown below. ansible version 1.8.2

   - name: copy init script      template: src=template/optimus_api_service.sh dest=/etc/init.d/optimus-api mode=0755 force=yes owner=root group=root 

i have tested following playbook , works.

my setup:

the user vagrant on machine vm allowed execute commands password-free sudo.

i created simple template , installed following playbook:

--- - name: test template   hosts: vm   gather_facts: no   remote_user: vagrant    vars:     bla: blub                # variable used in template    tasks:     - name:  copy init script       sudo: yes              # << have activate sudo       sudo_user: root        # << , provide user       template: src=template/test.j2 dest=/opt/test mode=0755 force=yes owner=root group=root 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -