尝试运行剧本。
剧本:
- name: copy files between hosts
hosts: all
tasks:
- name: copy file from ubuntu to rocky
synchronize:
src: /etc/hosts
dest: /tmp/hosts
mode: push
delegate_to: localhost
- name: check file
stat:
path: /tmp/hosts
register: statfile
- debug:
var: statfile
当我运行剧本时,出现错误:
ERROR! Unexpected Exception, this is probably a bug: cannot import name 'MAGIC_VARIABLE_MAPPING' from 'ansible.playbook.play_context' (/usr/local/lib/python3.10/dist-packages/ansible/playbook/play_context.py)
当我用复制替换同步时,它可以工作
在Ubuntu中,默认情况下/usr/local/lib/python3.*/dist-packages/
中没有
dist-packages
shell> cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=24.04
DISTRIB_CODENAME=noble
DISTRIB_DESCRIPTION="Ubuntu 24.04.1 LTS"
shell> tree /usr/local/lib/
/usr/local/lib/
└── python3.12
└── dist-packages
ansible 模块的默认位置是
/usr/lib/python3/dist-packages/ansible
shell> cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=24.04
DISTRIB_CODENAME=noble
DISTRIB_DESCRIPTION="Ubuntu 24.04.1 LTS"
shell> dpkg -l | grep ansible
ii ansible 9.2.0+dfsg-0ubuntu5 all Configuration management, deployment, and task execution system
ii ansible-core 2.16.3-0ubuntu2 all Configuration management, deployment, and task execution system
ii ansible-lint 6.17.2-1 all lint tool for Ansible playbooks
ii python3-ansible-compat 4.1.11-1 all Ansible compatibility goodies
shell> ansible --version | grep dist-packages
ansible python module location = /usr/lib/python3/dist-packages/ansible
shell> find /usr/lib/python3/dist-packages/ansible -name play_context.py
/usr/lib/python3/dist-packages/ansible/playbook/play_context.py
Python虚拟环境中的pip安装位置是
(env) > find /home/admin/env/lib/python3.12/site-packages/ -name play_context.py
/home/admin/env/lib/python3.12/site-packages/ansible/playbook/play_context.py
(env) > python3 -m pip list | grep ansible
ansible 10.3.0
ansible-compat 24.6.1
ansible-core 2.17.3
ansible-lint 24.7.0
ansible-pygments 0.1.1
ansible-runner 2.4.0
sphinx-ansible-theme 0.10.3