在使用Ansible Collections google.cloud.gcp_compute时,使用清单文件和行动手册的正确命令是什么。您可以在本文末尾的this article中找到一个与我使用的清单文件非常相似的示例
我正在使用这个update.yml攻略:
- name: Update apt-get repo and cache
apt: update_cache=yes force_apt_get=yes cache_valid_time=3600这是我的inventory-gcp_compute.yml清单文件:
plugin: google.cloud.gcp_compute
zones: # populate inventory with instances in these regions
- us-central1-a
projects:
- vpn-server-sasp
auth_kind: serviceaccount
scopes:
- 'https://www.googleapis.com/auth/cloud-platform'
- 'https://www.googleapis.com/auth/compute.readonly'
keyed_groups:
# Create groups from GCE labels
- prefix: gcp
key: labels
hostnames:
# List host by name instead of the default public ip
- name
compose:
# Set an inventory parameter to use the Public IP address to connect to the host
# For Private ip use "networkInterfaces[0].networkIP"
ansible_host: networkInterfaces[0].accessConfigs[0].natIP我尝试过以下命令:
ansible-playbook -i inventory-gcp_compute.yml update.yml我得到了这个错误:
ansible-playbook 2.9.14
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/cheo/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.17 (default, Jul 20 2020, 15:37:01) [GCC 7.5.0]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/cheo/sergio/ansible-gce/inventory-gcp_compute.yml as it did not pass its verify_file() method
virtualbox declined parsing /home/cheo/sergio/ansible-gce/inventory-gcp_compute.yml as it did not pass its verify_file() method
[WARNING]: * Failed to parse /home/cheo/sergio/ansible-gce/inventory-gcp_compute.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory
File "/usr/lib/python2.7/dist-packages/ansible/inventory/manager.py", line 280, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/inventory/yaml.py", line 112, in parse
raise AnsibleParserError('Plugin configuration YAML file, not YAML inventory')
[WARNING]: * Failed to parse /home/cheo/sergio/ansible-gce/inventory-gcp_compute.yml with constructed plugin: Incorrect plugin name in file: google.cloud.gcp_compute
File "/usr/lib/python2.7/dist-packages/ansible/inventory/manager.py", line 280, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/inventory/constructed.py", line 109, in parse
self._read_config_data(path)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/inventory/__init__.py", line 224, in _read_config_data
raise AnsibleParserError("Incorrect plugin name in file: %s" % config.get('plugin', 'none found'))
[WARNING]: Unable to parse /home/cheo/sergio/ansible-gce/inventory-gcp_compute.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
ERROR! 'apt' is not a valid attribute for a Play
The error appears to be in '/home/cheo/sergio/ansible-gce/update.yml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Update apt-get repo and cache
^ here发布于 2021-01-07 08:11:47
检查一下文档。它正在寻找以.gcp_compute.yml或.gcp.yml结尾的文件,因此,虽然inventory.gcp_compute.yml符合条件,但inventory-gcp_compute.yml不符合条件。你得到的错误表明该文件不是一个清单,但是没有一个插件解析器声明它。
https://stackoverflow.com/questions/64276611
复制相似问题