创建 GCP 资源并获取 IP 地址 [英] Creation GCP ressource and get IP adresse

查看:37
本文介绍了创建 GCP 资源并获取 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在 GCP 上创建新的 nexus 服务器.我决定使用 nfs 点进行数据存储.一切都必须用 ansible 完成(实例已经用 terraform 创建了)

I must create new nexus server on GCP. I have decided to use nfs point for datastorage. All must be done with ansible ( instance is already created with terraform)

我必须获取 GCP 设置的动态 IP 并创建挂载点.

I must get the dynamic IP setted by GCP and create the mount point.

使用 gcloud 命令运行良好,但如何仅获取 IP 信息?

It's working fine with gcloud command, but how to get only IP info ?

代码:

- name: get info
  shell: gcloud filestore instances describe nfsnexus --project=xxxxx --zone=xxxxx --format='get(networks.ipAddresses)'
  register: ip


- name: Print all available facts
  ansible.builtin.debug:
    msg: "{{ip}}"

结果:

ok: [nexus-ppd.preprod.d-aim.com] => {
    "changed": false,
    "msg": {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python3"
        },
        "changed": true,
        "cmd": "gcloud filestore instances describe nfsnexus --project=xxxxx --zone=xxxxx  --format='get(networks.ipAddresses)'",
        "delta": "0:00:00.763235",
        "end": "2021-03-14 00:33:43.727857",
        "failed": false,
        "rc": 0,
        "start": "2021-03-14 00:33:42.964622",
        "stderr": "",
        "stderr_lines": [],
        "stdout": "['1x.x.x.1xx']",
        "stdout_lines": [
            "['1x.x.x.1xx']"
        ]
    }
}

谢谢

推荐答案

只需使用正确的格式字符串,例如.获取第一个IP:

Just use the proper format string, eg. to get the first IP:

--format='get(networks.ipAddresses[0])'

这篇关于创建 GCP 资源并获取 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆