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

synchronize with use_ssh_args: Jinja expressions kept in 'ansible_ssh_common_args' #222

Closed
rnowagk opened this issue Jul 13, 2021 · 4 comments · Fixed by #223
Closed

synchronize with use_ssh_args: Jinja expressions kept in 'ansible_ssh_common_args' #222

rnowagk opened this issue Jul 13, 2021 · 4 comments · Fixed by #223
Labels
bug This issue/PR relates to a bug. has_pr verified This issue has been verified/reproduced by maintainer

Comments

@rnowagk
Copy link

rnowagk commented Jul 13, 2021

SUMMARY

A play with synchronize and 'use_ssh_args', which is working in ansible-2.8.19 fails now with messages like:

fatal: [ish90-nagios01]: FAILED! => {"changed": false, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh=/usr/bin/ssh -S none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null {{ ssh_key_args }} --rsync-path=sudo rsync --out-format=<<CHANGED>>%i %n%L /home/centos/git/ishXX/sync-test/inventory.ini [email protected]:/tmp/inventory.ini", "msg": "ssh: Could not resolve hostname {{: Name or service not known\r\nrsync: connection unexpectedly closed (0 bytes received so far) [sender]\nrsync error: unexplained error (code 255) at io.c(226) [sender=3.1.2]\n", "rc": 255}

The reported 'cmd' and "ssh: Could not resolve hostname {{: indicates that my 'ansible_ssh_common_args: "{{ssh_key_args}}" is no longer subject to Jinja processing, but passed as is.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

synchronize

ANSIBLE VERSION
ansible [core 2.11.2]
  config file = None
  configured module search path = ['/home/centos/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/rh/rh-python38/root/usr/local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/centos/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/rh/rh-python38/root/usr/local/bin/ansible
  python version = 3.8.6 (default, Oct 27 2020, 09:13:12) [GCC 9.3.1 20200408 (Red Hat 9.3.1-2)]
  jinja version = 3.0.1
  libyaml = True

COLLECTION VERSION

# /usr/share/ansible/collections/ansible_collections
Collection    Version
------------- -------
ansible.posix 1.2.0

CONFIGURATION
<empty>
OS / ENVIRONMENT

CentOS 7.9 on control an managed nodes

STEPS TO REPRODUCE

Configure some Jinja expression in ansible_ssh_common_args and run a 'synchronize_task' with 'use_ssh_args: yes'

inventory.ini:
ish90-test  computer_name=ish90service.northeurope.cloudapp.azure.com

group_vars/all.yml:
ansible_user: centos
ssh_key_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
ansible_ssh_common_args: "{{ ssh_key_args }}"
ansible_host:            "{{ computer_name }}"

sync.yml:
- hosts: ish90-test
  become: true
  become_method: sudo
  gather_facts: false

  tasks:
    - synchronize:
        src: inventory.ini
        dest: /tmp/inventory.ini
        use_ssh_args: yes
EXPECTED RESULTS

A working rsync command, as with ansible-2.8.19:

ansible-playbook -i inventory.ini sync.yml -vvv
...
changed: [ish90-test] => {
    "changed": true,
    "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh=/usr/bin/ssh -S none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -C -o
ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no --rsync-path=sudo rsync --out-format=<<CHANGED>>%i %n%L /mn
t/d/git/ishXX/sync-test/inventory.ini [email protected]:/tmp/inventory.ini",
...
ACTUAL RESULTS

Fails ultimately with "ssh: Could not resolve hostname {{'; obviously due to a Jinja expression in the rsync command

ansible-playbook -i inventory.ini sync.yml -vvvv
ansible-playbook [core 2.11.2]
  config file = None
  configured module search path = ['/home/centos/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/rh/rh-python38/root/usr/local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/centos/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/rh/rh-python38/root/usr/local/bin/ansible-playbook
  python version = 3.8.6 (default, Oct 27 2020, 09:13:12) [GCC 9.3.1 20200408 (Red Hat 9.3.1-2)]
  jinja version = 3.0.1
  libyaml = True
No config file found; using defaults
setting up inventory plugins
host_list declined parsing /home/centos/git/ishXX/sync-test/inventory.ini as it did not pass its verify_file() method
auto declined parsing /home/centos/git/ishXX/sync-test/inventory.ini as it did not pass its verify_file() method
yaml declined parsing /home/centos/git/ishXX/sync-test/inventory.ini as it did not pass its verify_file() method
Parsed /home/centos/git/ishXX/sync-test/inventory.ini inventory source with ini plugin
redirecting (type: action) ansible.builtin.synchronize to ansible.posix.synchronize
Loading collection ansible.posix from /usr/share/ansible/collections/ansible_collections/ansible/posix
Loading callback plugin default of type stdout, v2.0 from /opt/rh/rh-python38/root/usr/local/lib/python3.8/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: sync.yml *********************************************************************************************************************************************
Positional arguments: sync.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/home/centos/git/ishXX/sync-test/inventory.ini',)
forks: 5
1 plays in sync.yml

PLAY [ish90-test] **********************************************************************************************************************************************
META: ran handlers
redirecting (type: action) ansible.builtin.synchronize to ansible.posix.synchronize

TASK [synchronize] *********************************************************************************************************************************************
task path: /home/centos/git/ishXX/sync-test/sync.yml:7
redirecting (type: action) ansible.builtin.synchronize to ansible.posix.synchronize
redirecting (type: action) ansible.builtin.synchronize to ansible.posix.synchronize
<ish90service.northeurope.cloudapp.azure.com> ESTABLISH LOCAL CONNECTION FOR USER: centos
<ish90service.northeurope.cloudapp.azure.com> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/centos/.ansible/tmp/ansible-local-2639msti3hy5 `"&& mkdir "` echo /home/centos/.ansible/tmp/ansible-local-2639msti3hy5/ansible-tmp-1626180361.6669338-2645-14192139122753 `" && echo ansible-tmp-1626180361.6669338-2645-14192139122753="` echo /home/centos/.ansible/tmp/ansible-local-2639msti3hy5/ansible-tmp-1626180361.6669338-2645-14192139122753 `" ) && sleep 0'
Using module file /usr/share/ansible/collections/ansible_collections/ansible/posix/plugins/modules/synchronize.py
<ish90service.northeurope.cloudapp.azure.com> PUT /home/centos/.ansible/tmp/ansible-local-2639msti3hy5/tmpm8f79k24 TO /home/centos/.ansible/tmp/ansible-local-2639msti3hy5/ansible-tmp-1626180361.6669338-2645-14192139122753/AnsiballZ_synchronize.py
<ish90service.northeurope.cloudapp.azure.com> EXEC /bin/sh -c 'chmod u+x /home/centos/.ansible/tmp/ansible-local-2639msti3hy5/ansible-tmp-1626180361.6669338-2645-14192139122753/ /home/centos/.ansible/tmp/ansible-local-2639msti3hy5/ansible-tmp-1626180361.6669338-2645-14192139122753/AnsiballZ_synchronize.py && sleep 0'
<ish90service.northeurope.cloudapp.azure.com> EXEC /bin/sh -c '/opt/rh/rh-python38/root/usr/bin/python3 /home/centos/.ansible/tmp/ansible-local-2639msti3hy5/ansible-tmp-1626180361.6669338-2645-14192139122753/AnsiballZ_synchronize.py && sleep 0'
<ish90service.northeurope.cloudapp.azure.com> EXEC /bin/sh -c 'rm -f -r /home/centos/.ansible/tmp/ansible-local-2639msti3hy5/ansible-tmp-1626180361.6669338-2645-14192139122753/ > /dev/null 2>&1 && sleep 0'
fatal: [ish90-test]: FAILED! => {
    "changed": false,
    "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh=/usr/bin/ssh -S none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null {{ ssh_key_args }} --rsync-path=sudo rsync --out-format=<<CHANGED>>%i %n%L /home/centos/git/ishXX/sync-test/inventory.ini [email protected]:/tmp/inventory.ini",
    "invocation": {
        "module_args": {
            "_local_rsync_password": null,
            "_local_rsync_path": "rsync",
            "_substitute_controller": false,
            "archive": true,
            "checksum": false,
            "compress": true,
            "copy_links": false,
            "delete": false,
            "dest": "[email protected]:/tmp/inventory.ini",
            "dest_port": null,
            "dirs": false,
            "existing_only": false,
            "group": null,
            "link_dest": null,
            "links": null,
            "mode": "push",
            "owner": null,
            "partial": false,
            "perms": null,
            "private_key": null,
            "recursive": null,
            "rsync_opts": [],
            "rsync_path": "sudo rsync",
            "rsync_timeout": 0,
            "set_remote_user": true,
            "src": "/home/centos/git/ishXX/sync-test/inventory.ini",
            "ssh_args": "{{ ssh_key_args }}",
            "ssh_connection_multiplexing": false,
            "times": null,
            "verify_host": false
        }
    },
    "msg": "ssh: Could not resolve hostname {{: Name or service not known\r\nrsync: connection unexpectedly closed (0 bytes received so far) [sender]\nrsync error: unexplained error (code 255) at io.c(226) [sender=3.1.2]\n",
    "rc": 255
}

PLAY RECAP *****************************************************************************************************************************************************
ish90-test                 : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

@Akasurde
Copy link
Member

@rnowagk Thanks for reporting this issue. With PR ansible/ansible#73708, parameters related to SSH were removed. From my understanding, we need to come up with parameters with synchronize module.

@Akasurde Akasurde added bug This issue/PR relates to a bug. verified This issue has been verified/reproduced by maintainer labels Jul 14, 2021
@Akasurde
Copy link
Member

As a workaround stick to Ansible 2.10 and lower.

Akasurde added a commit to Akasurde/ansible.posix that referenced this issue Jul 14, 2021
SSH configuration migrated from Ansible configuration to
SSH connection configuration. Make ``synchronize`` understand
this.

Fixes: ansible-collections#222

Signed-off-by: Abhijeet Kasurde <[email protected]>
@Akasurde
Copy link
Member

@rnowagk Could you please check if PR #223 works for you and let me know? Thanks in advance.

@rnowagk
Copy link
Author

rnowagk commented Jul 14, 2021

@Akasurde Awesome! Fixed the testcase and my real scenario (which is with a dynamic Azure inventory and a lengthy SSH ProxyCommand in the 'ssh_common_args').

Akasurde added a commit to Akasurde/ansible.posix that referenced this issue Jul 21, 2021
SSH configuration migrated from Ansible configuration to
SSH connection configuration. Make ``synchronize`` understand
this.

Fixes: ansible-collections#222

Signed-off-by: Abhijeet Kasurde <[email protected]>
Akasurde added a commit to Akasurde/ansible.posix that referenced this issue Aug 9, 2021
SSH configuration migrated from Ansible configuration to
SSH connection configuration. Make ``synchronize`` understand
this.

Fixes: ansible-collections#222

Signed-off-by: Abhijeet Kasurde <[email protected]>
Akasurde added a commit to Akasurde/ansible.posix that referenced this issue Aug 10, 2021
SSH configuration migrated from Ansible configuration to
SSH connection configuration. Make ``synchronize`` understand
this.

Fixes: ansible-collections#222

Signed-off-by: Abhijeet Kasurde <[email protected]>
Akasurde added a commit that referenced this issue Aug 11, 2021
SSH configuration migrated from Ansible configuration to
SSH connection configuration. Make ``synchronize`` understand
this.

Fixes: #222

Signed-off-by: Abhijeet Kasurde <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug. has_pr verified This issue has been verified/reproduced by maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants