大佬教程收集整理的这篇文章主要介绍了Ansible 和 GCP 使用事实 GCP 文件存储模块,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
编辑:我可以使用 gcloud,但看不到如何在 var 中获取 ip。
gcloud filestore instances describe nfsxxxd --project=dxxxxt-2xxx --zone=xxxx-xx-b --format='get(networks.ipaddresses)'
['1xx.x.x.1']
我正在尝试创建文件存储并在实例中安装它。 我在尝试获取这个新文件存储的 ipadress 时遇到问题。
我正在使用 ansible 模块,并且在 ansible 命令中使用 -v 时可以看到输出。
Ansible 模块文件存储:
- name: get info on an instance
gcp_filestore_instance_info:
zone: xxxxx-xxxx-b
project: dxxxxx-xxxxxx
auth_kind: serviceaccount
service_account_file: "/root/dxxxt-xxxxxxx.Json"
Ansible 输出:
ok: [xxxxxx-xxxxxx] => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": false,"resources": [{"createTime": "2021-03-12T13:40:36.438598373Z","fileShares": [{"capacityGb": "1024","name": "nfxxxxx"}],"name": "projects/xxx-xxxxx/LOCATIOns/xxxxxxx-b/instances/xxxxx-xxx","networks": [{"ipaddresses": ["1xx.x.x.x"],"modes": ["MODE_IPV4"],"network": "admin","reservedIpRange": "1xx.x.x.x/29"}],"state": "READY","tIEr": "BASIC_HDD"},{"createTime": "2021-03-10T11:13:00.111631131Z","name": "nfsnxxxxx","nfsExportoptions": [{"accessMode": "READ_WRITE","ipRanges": ["xxx.xx.xx.xxx"],"squashMode": "no_root_SQUASH"}]}],"name": "projects/dxxx-xxxxx/LOCATIOns/xxxxx/instances/innxxxx","networks": [{"ipaddresses": ["x.x.x.x."],...
我试过这个,但它不起作用。 Ansible 任务:
- name: print fact filestore
deBUG:
msg: "{{ansible_facts.resources.createTimE}}"
fatal: [nxxxxxxx]: Failed! => {"msg": "The task includes an option with an undefined variable. The error was: 'Dict object' has no attribute 'resources'\n\nThe error appears to be in '/root/xxxxxxx/tasks/main.yml': line 11,column 3,but may\nbe elsewhere in the file depending on the exact Syntax problem.\n\nThe offending line appears to be:\n\n\n- name: print fact filestore\n ^ here\n"}
谢谢
如果我相信您的答案的示例输出,信息将在您的任务结果的 resources
键中返回。我无法测试自己,但我相信以下内容应该符合您的期望。
请注意,resources
是一个字典列表。在下面的示例中,我将从列表的第一个元素访问信息。如果您需要其他内容(例如所有 createTime
... 的列表)或循环遍历这些对象,您可以从这个示例进行扩展。
- name: get info on an instance
gcp_filestore_instance_info:
zone: xxxxx-xxxx-b
project: dxxxxx-xxxxxx
auth_kind: serviceaccount
service_account_file: "/root/dxxxt-xxxxxxx.json"
register: instance_info
- name: show create time for first resource
debug:
msg: "{{ instance_info.resources.0.createTime }}"
- name: show first ip of first network of first resource
debug:
msg: "{{ instance_info.resources.0.networks.0.ipaddresses.0 }}"
以上是大佬教程为你收集整理的Ansible 和 GCP 使用事实 GCP 文件存储模块全部内容,希望文章能够帮你解决Ansible 和 GCP 使用事实 GCP 文件存储模块所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。