试图执行以下 Ansible 剧本:
- name: Create an instance
hosts: localhost
gather_facts: no
vars:
gcp_project:
gcp_cred_kind: serviceaccount
gcp_cred_file: /users/artyom/my_auth.json
zone: "us-central1-a"
region: "us-central1"
tasks:
- name: create a disk
gcp_compute_disk:
name: 'disk-instance1'
size_gb: 20
source_image: 'projects/rocky-linux-cloud/global/images/family/rocky-linux-8'
zone: "{{ zone }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: disk
- name: create a address
gcp_compute_address:
name: 'address-instance1'
region: "{{ region }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: address
- name: create a instance
gcp_compute_instance:
state: present
name: test-vm12
machine_type: n1-standard-1
disks:
- auto_delete: true
boot: true
source: "{{ disk }}"
network_interfaces:
- network: null # use default
access_configs:
- name: 'External NAT'
nat_ip: "{{ address }}"
type: 'ONE_TO_ONE_NAT'
zone: "{{ zone }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
register: instance
- name: Wait for SSH to come up
wait_for: host={{ address.address }} port=22 delay=10 timeout=60
- name: Add host to groupname
add_host: hostname={{ address.address }} groupname=new_instances
- name: nginx | Install latest nginx
yum:
name: nginx
state: latest
一切都很完美,直到最后一个块(yum)。无论我对 Python 版本做什么,这都是我得到的错误:
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Could not import the dnf python module using /Users/artyom/opt/anaconda3/bin/python (3.8.8 (default, Apr 13 2021, 12:59:45) [Clang 10.0.0 ]). Please install `python3-dnf` or `python2-dnf` package or ensure you have specified the correct ansible_python_interpreter. (attempted ['/usr/libexec/platform-python', '/usr/bin/python3', '/usr/bin/python2', '/usr/bin/python'])", "results": []}
我尝试过使用多个包管理器(例如 ASDF、PYENV 等)、python 版本、下载丢失的“dnf 模块”并通过主机文件指向它,或者更改
ansible_python_interpreter
要自动,auto_legacy,指向 python 位置,恰好是先前下载的 python-dnf 模块存储等。
我已经在这个问题上苦苦挣扎了 2 周,所有其他 SOF 和其他网站谷歌搜索都没有解决任何问题。
目前我正在通过 Anaconda 使用 Python。
python - V output is:
Python 3.8.8
还尝试添加“use_backend =”(它的所有可能版本)。
修改对主机文件的访问权限并更改其内容后,我得到以下信息:
回溯(最后一次调用):文件“/Users/artyom/opt/anaconda3/bin/ansible-playbook”,第 62 行,在 import ansible.constants as C 文件“/Users/artyom/.local/lib/python3. 8/site-packages/ansible/constants.py”,第 181 行,在 config = ConfigManager() 文件“/Users/artyom/.local/lib/python3.8/site-packages/ansible/config/manager.py”中,第 302 行,在 init self._config_file = find_ini_config_file(self.WARNINGS) 文件“/Users/artyom/.local/lib/python3.8/site-packages/ansible/config/manager.py”中,第 244 行,在 find_ini_config_file potential_paths.append(unfrackpath("~/.ansible.cfg", follow=False)) 文件 "/Users/artyom/.local/lib/python3.8/site-packages/ansible/utils/path.py", 行50、在 unfrackpath b_basedir = to_bytes(os.getcwd(), errors='surrogate_or_strict') PermissionError:[Errno 13] 权限被拒绝