【问题标题】:Creation GCP ressource and get IP adresse创建 GCP 资源并获取 IP 地址
【发布时间】:2021-03-14 10:05:19
【问题描述】:

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

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

使用 gcloud 命令可以正常工作,但如何仅获取 IP 信息?

代码:

- 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:"stdout": "['1x.x.x.1xx']"
  • 正确 :D ,我正在寻找让标准输出在 var 中注册它。应该使用某些行“{{ip.stdout}}”?

标签: google-cloud-platform ansible nexus


【解决方案1】:

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

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

【讨论】:

  • 亲爱的返回空行。我使用的初始命令工作正常,我只需要从 ansible 结果中获得正确的返回
【解决方案2】:

找到解决方案只需添加以下内容:

- name:
  debug:
    msg:  "{{ip.stdout_lines}}"

我觉得自己好蠢 :(,我必须在凌晨 2 点后停下来工作 :)

谢谢

【讨论】:

    猜你喜欢
    • 2017-03-09
    • 2011-04-05
    • 2010-11-04
    • 1970-01-01
    • 1970-01-01
    • 2011-10-11
    • 1970-01-01
    • 2021-07-06
    • 2013-01-16
    相关资源
    最近更新 更多