ansible.posix
ansible.posix copied to clipboard
synchronize: if `ansible_host` is jinja expression - module threats is as string and fails
SUMMARY
Module raise error, if ansible_port
is jinja expression:
msg: 'argument ''dest_port'' is of type <class ''str''> and we were unable to convert to int: <class ''str''> cannot be converted to an int'
ISSUE TYPE
- Bug Report
COMPONENT NAME
synchronize
ANSIBLE VERSION
ansible [core 2.13.1]
config file = None
configured module search path = ['~/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = ~/Library/Python/3.9/lib/python/site-packages/ansible
ansible collection location = ~/.ansible/collections:/usr/share/ansible/collections
executable location = /opt/homebrew/bin/ansible
python version = 3.9.12 (main, Mar 26 2022, 15:44:31) [Clang 13.1.6 (clang-1316.0.21.2)]
jinja version = 3.0.3
libyaml = True
COLLECTION VERSION
# ~/Library/Python/3.9/lib/python/site-packages/ansible_collections
Collection Version
------------- -------
ansible.posix 1.4.0
CONFIGURATION
CACHE_PLUGIN(/path-to-folder/ansible.cfg) = yaml
CACHE_PLUGIN_CONNECTION(/path-to-folder/ansible.cfg) = .cache
CALLBACKS_ENABLED(/path-to-folder/ansible.cfg) = ['ansible.posix.profile_tasks']
DEFAULT_FORCE_HANDLERS(/path-to-folder/ansible.cfg) = True
DEFAULT_HOST_LIST(/path-to-folder/ansible.cfg) = ['/path-to-folder/hosts.yaml']
DEFAULT_JINJA2_NATIVE(/path-to-folder/ansible.cfg) = True
DEFAULT_LOAD_CALLBACK_PLUGINS(/path-to-folder/ansible.cfg) = True
DEFAULT_STDOUT_CALLBACK(/path-to-folder/ansible.cfg) = yaml
HOST_KEY_CHECKING(/path-to-folder/ansible.cfg) = False
INTERPRETER_PYTHON(/path-to-folder/ansible.cfg) = auto_silent
OS / ENVIRONMENT
MacOS/12.4 (21F79)/M1 (this is not OS specific issue)
STEPS TO REPRODUCE
- name: test
hosts: host
become: yes
vars:
ssh_port: 2222
ansible_port: "{{ ssh_port }}"
tasks:
- name: sync
ansible.posix.synchronize:
# dest_port: "{{ ansible_port }}"
mode: pull
src: "user@host/file"
dest: "~/"
EXPECTED RESULTS
All works.
(if in PB uncomment line # dest_port: "{{ ansible_port }}"
or comment line ansible_port: "{{ ssh_port }}"
- all worked fine)
ACTUAL RESULTS
Jinja expression "{{ ssh_port }}" of variable ansible_port
not substituted and sends to module as string (see below line dest_port: '{{ ssh_port }}'
):
https://github.com/ansible-collections/ansible.posix/blob/a65807edc322ec403eb73e006aa9f6e2172026a3/plugins/action/synchronize.py#L265-L268
fatal: [host]: FAILED! => changed=false
invocation:
module_args:
_local_rsync_password: null
_local_rsync_path: rsync
_substitute_controller: false
archive: true
checksum: false
compress: true
copy_links: false
delay_updates: true
delete: false
dest: ~
dest_port: '{{ ssh_port }}'
dirs: false
existing_only: false
group: null
link_dest: null
links: null
mode: pull
owner: null
partial: false
perms: null
private_key: null
recursive: null
rsync_opts: []
rsync_path: sudo -u user rsync
rsync_timeout: 0
set_remote_user: true
src: 'user@host/file'
ssh_args: null
ssh_connection_multiplexing: false
times: null
verify_host: false
msg: 'argument ''dest_port'' is of type <class ''str''> and we were unable to convert to int: <class ''str''> cannot be converted to an int'
Have the same issue, my temporary workaround:
- name: test
hosts: host
vars:
ssh_port: 2222
ansible_port: "{{ ssh_port }}"
tasks:
- name: sync
ansible.posix.synchronize:
dest_port: "{{ lookup('ansible.builtin.vars', 'ansible_port') }}"
mode: pull
src: user@host/file
dest: ~/
Issue title here is about ansible_host
, shouldn't it should be ansible_port
?
Got the same issue with ansible_user
, probably occurs with all connection parameters.