如何从 openstack.cloud.server 模块中的文件传递用户数据?

问题描述 投票:0回答:0

我正在尝试使用 openstack.cloud.server 模块在 openstack 上实例化一个 VM 实例。我想从文件 (userdata.txt) 传递用户数据,而不是像下面突出显示的那样以原始形式传递它:

- name: launch a compute instance
  hosts: localhost
  tasks:
    - name: launch an instance
      openstack.cloud.server:
        name: vm1
        state: present
        image: "Ubuntu Server 14.04"
        flavor: "P-1"
        network: "Production"
        userdata: |
          **{%- raw -%}#!/bin/bash
          echo "  up ip route add 10.0.0.0/8 via {% endraw -%}{{ intra_router }}{%- raw -%}" >> /etc/network/interfaces.d/eth0.conf
          echo "  down ip route del 10.0.0.0/8" >> /etc/network/interfaces.d/eth0.conf
          ifdown eth0 && ifup eth0**
          {% endraw %}**

你能建议我怎样才能做到这一点吗?我尝试使用查找,但它不起作用,因为它正在更改用户数据内容的格式。

"{{ lookup('ansible.builtin.file', '/tmp/userdata.txt') }}"

ansible ansible-2.x ansible-inventory ansible-facts ansible-template
© www.soinside.com 2019 - 2024. All rights reserved.