Code Monkey home page Code Monkey logo

Comments (1)

jooola avatar jooola commented on September 25, 2024

Hi @liKe2k1,

I was able to reproduce your problem, and the server gets a random/first IP from the "net-region" network IP range (10.145.0.0/16).

To attach the desired IP (10.145.1.11), you can try removing the private_networks entry when creating the server. When using this field, you will ask to attach an IP within the IP range of that network (10.145.0.0/16). And let the hetzner.hcloud.hcloud_server_network module attach the correct IP to the server.

Here is my reproduction playbook:

- hosts: all
  vars:
    hcloud_token: some_token

    network_name: net-region
    network_region: 10.145.0.0/16
    default_os: rocky-9
    region: fsn1

    subnets:
      - name: management
        ip_range: 10.145.1.0/24
      - name: kubernetes
        ip_range: 10.145.5.0/24
      - name: client
        ip_range: 10.145.10.0/24

    servers:
      - name: lvjump01
        ip: 10.145.1.11
        network: management
        type: cpx11
  tasks:
    - name: Create the internal network
      hetzner.hcloud.hcloud_network:
        api_token: "{{ hcloud_token }}"
        name: "{{ network_name }}"
        ip_range: "{{ network_region }}"
        state: present
      run_once: true
      delegate_to: localhost

    - name: Create subnets
      hetzner.hcloud.hcloud_subnetwork:
        api_token: "{{ hcloud_token }}"
        network: "{{ network_name }}"
        ip_range: "{{ item.ip_range }}"
        network_zone: eu-central
        type: cloud
        state: present
      with_items: "{{ subnets }}"
      run_once: true
      delegate_to: localhost

    - name: Create a server
      hetzner.hcloud.hcloud_server:
        api_token: "{{ hcloud_token }}"
        name: "{{ servers[0].name }}"
        server_type: "{{ servers[0].type }}"
        image: "{{ default_os }}"
        location: "{{ region }}"
        ## Comment this out to prevent attaching a random IP from the "{{ network_name }}" ip range.
        #private_networks:
        #  - "{{ network_name }}"
        state: started
      delegate_to: localhost
      run_once: true

    - name: Attach a private ip
      hetzner.hcloud.hcloud_server_network:
        api_token: "{{ hcloud_token }}"
        network: "{{ network_name }}"
        server: "{{ servers[0].name }}"
        ip: "{{ servers[0].ip }}"
        state: present
      delegate_to: localhost
      run_once: true

I hope this helps ?

from hetzner.hcloud.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.