Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to correctly use ansible.uildin.synchronize with certain user? #552

Open
gsg-git opened this issue Jun 21, 2024 · 0 comments
Open

How to correctly use ansible.uildin.synchronize with certain user? #552

gsg-git opened this issue Jun 21, 2024 · 0 comments

Comments

@gsg-git
Copy link

gsg-git commented Jun 21, 2024

Hello!
I have a playbook where i want to transfer from a remote host to another host and use a service user and its keys in the default location /home/user/.ssh i can move files when i put the keys to ~/.ssh/, but with my other playbook it stops at the sncronize task and just stops when i end the template and the log just stops and schows nor errors.
The Playbook:
`---

  • name: Generate SSH keypair on remote hosts and distribute keys
    hosts:

    • 192.168.151.141

    • 192.168.151.237
      become: true
      tasks:

    • name: Create a "sync_src" group
      ansible.builtin.group_by:
      key: sync_src
      when: ansible_default_ipv4.address == '192.168.151.237'

    • name: Create a "sync_dst" group
      ansible.builtin.group_by:
      key: sync_dst
      when: ansible_default_ipv4.address == '192.168.151.141'

  • name: Create SSH keypair in /tmp
    hosts: localhost
    tasks:

    • name: Create SSH keypair in /tmp
      ansible.builtin.openssh_keypair:
      path: /tmp/id_rsa_remcpyusr
      type: rsa
      force: true
      comment: "remcpyusr"
      run_once: true
  • name: Distribute the SSH public key
    hosts: sync_dst
    tasks:

    • name: Distribute the SSH public key
      ansible.builtin.copy:
      src: /tmp/id_rsa_remcpyusr.pub
      dest: /home/remcpyusr/.ssh/authorized_keys
      owner: remcpyusr
      mode: '0644'
      force: yes
  • name: Distribute the SSH private key
    hosts: sync_src
    tasks:

    • name: Distribute the SSH private key
      ansible.builtin.copy:
      src: /tmp/id_rsa_remcpyusr
      dest: /home/remcpyusr/.ssh/id_rsa
      owner: remcpyusr
      mode: '0600'
      force: yes
  • name: Synchronize files to target host
    hosts: sync_dst
    tasks:

    • name: Synchronize files to target host
      ansible.builtin.synchronize:
      src: '{{ item }}'
      dest: remcpyusr@{{ ansible_default_ipv4.address }}:{{ item }}
      rsync_opts:
      - "--rsh='ssh -i /home/remcpyusr/.ssh/id_rsa'"
      delegate_to: '{{ groups["sync_src"] | random }}'
      when: "'sync_dst' in group_names"
      loop:
      • /tmp/test.txt`

job_3856.txt
The really nice peaople in the ansible forum have sadly no idea what the issue could be.

Im very grateful for your input!!

MDuerre

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant