Rundeck- Ansible playbook mode - how to achieve local task with another user

136 views
Skip to first unread message

Ben .T.George

unread,
Jun 19, 2022, 9:53:32 AM6/19/22
to rundeck-discuss
Hello,

i am new to rundeck and trying to get some files from remote host by using Ansible playbook.

i can able to list files and get the files from remote to local server, were Rundeck runs. currently i am fetching files to /tmp/ . I notices that local files are owned by user:group rundeck

Eventually i want this files to move under another users home directory, which rundeck user doesn't have access  

Is there any way to invoke another user inside this task?

Ben .T.George

unread,
Jun 19, 2022, 9:56:56 AM6/19/22
to rundeck-discuss
Here is my ansible code

---
- hosts: etl12.example.com
  remote_user: ansible
  become: yes
  become_user: root
  become_method: sudo
  gather_facts: yes
  connection: ssh
  tasks:
  - name: Update file in remote server
    block:
      - name: find ICM files
        find:
          path: /data1/dw/ftpuser/Varicent_Files/ICM_CC
          patterns: "*.csv"
        register: ICM_CC_FILE

      - name: update to file
        lineinfile:
          path: /data1/dw/ftpuser/Varicent_Files/ICM_CC/ICM_Transfer_History
          state: present
          create: yes
          line: "{{ item.path }}"
        register: ICM_CC_file_update
        with_items:
        - "{{ ICM_CC_FILE.files }}"
    delegate_to: etl12.example.com
   
    - debug:
        msg: "{{ ICM_CC_FILE.files }}"
      when: ICM_CC_file_update.changed
  - name: Transfer files from remote to Local
    fetch:
      src: "{{ item.path }}"
      dest: /tmp/
      flat: yes
    with_items:
    - "{{ tarfilename.files }}"
   
  - debug:
      msg: "{{ ICM_CC_FILE.files }}"
    when: ICM_CC_file_update.changed
  - debug: var=item.path
    with_items: "{{ ICM_CC_FILE.files }}"


rac...@rundeck.com

unread,
Jun 22, 2022, 9:32:08 AM6/22/22
to rundeck-discuss
Hi Ben,

Maybe a good approach is to put the files on `/tmp` and then use this plugin (using a sudo command step or script step) to move the files to another user.

Regards!
Reply all
Reply to author
Forward
0 new messages