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

查看:87
本文介绍了创建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天全站免登陆