Code Monkey home page Code Monkey logo

Comments (8)

samiksha1191 avatar samiksha1191 commented on June 16, 2024

Hi @apricote can you please here as I am blocked for long time now on this issue. your help here is greatly appreciated.

from hetzner.hcloud.

jooola avatar jooola commented on June 16, 2024

Hello @samiksha1191

I think the error you are facing is because one of the server or network does not exist (is not found). The error should be improved, I'll fix this.

But is unrelated to your questions: here are a few comments for the code you provided:

- name: Create a basic network
  hetzner.hcloud.hcloud_network:
    name: "{{ item.name }}"
    ip_range: "{{ item.ip_range }}"
    state: "{{ infrastructure_state }}"
    api_token: "{{ hcloud_token }}"
  with_items: "{{ networks }}"

- name: Create a basic subnetwork
  # Make sure to use fqcn when calling the collection modules: hetzner.hcloud.hcloud_subnetwork
  hcloud_subnetwork:
    # I assume you are refering to {{ networks[0].name }}
    network: network1
    # You should use a different ip_range for your network and subnetwork, e.g.
    # 10.0.0.0/8 for the network and only a /16 or /24 for a subnetwork, say 10.0.1.0/24
    ip_range: "{{ item.ip_range }}"
    network_zone: eu-central
    type: cloud
    state: present
    api_token: "{{ hcloud_token }}"

- name: Create a basic server
  # Make sure to use fqcn when calling the collection modules: hetzner.hcloud.hcloud_server
  hcloud_server:
    name: my-server
    server_type: cx11
    image: ubuntu-22.04
    state: present
    enable_ipv4: false
    enable_ipv6: false
    datacenter: nbg1-dc3
    # This will automatically attach a random private ip from the subnet to your server, since you
    # want to specific the private IP yourself in the next task, you should not use this
    # argument.
    private_networks:
      - network1
    api_token: "{{ hcloud_token }}"

- name: Attach a server to a private network
  # Make sure to use fqcn when calling the collection modules: hetzner.hcloud.hcloud_server_network
  hcloud_server_network:
    # I assume you are refering to {{ networks[0].name }}
    network: network1
    server: my-server
    ip: 10.0.1.10
    state: present
    api_token: "{{ hcloud_token }}"

from hetzner.hcloud.

jooola avatar jooola commented on June 16, 2024

Related to #255

from hetzner.hcloud.

samiksha1191 avatar samiksha1191 commented on June 16, 2024

Hi @jooola Please don't mark the ticket as closed just yet as the problem is not solved until yet at my end. Allow me sometime until today EOD to confirm back.

from hetzner.hcloud.

samiksha1191 avatar samiksha1191 commented on June 16, 2024

Hi @jooola If i am following the instruction you gave above then yes my server now has a private IP of my choice but it is still coming up with a public IP because I can not keep both as false.

enable_ipv4
enable_ipv6

so i commented them in the code but then now it is assuming that since i have not declared any value for the above two parameters, so it is by default assigning one ipv4 address.

In my use case I d not want to have any public IP attached to the server at all. can you please tell me how do i achieve the same?

FYI, my current code looks like below.

**_- name: Create a basic server
  hcloud_server:
    name: my-server
    server_type: cx11
    image: ubuntu-22.04
    state: present                                            
    # enable_ipv4: false
    # enable_ipv6: false
    datacenter: nbg1-dc3
    #private_networks:
       #- network1
    api_token: "{{ hcloud_token }}"

- name: Create a server network and specify the ip address
  hcloud_server_network:
    network: network1
    server: my-server 
    ip: 10.0.1.10
    state: present
    api_token: "{{ hcloud_token }}"_**

from hetzner.hcloud.

samiksha1191 avatar samiksha1191 commented on June 16, 2024

Hi @jooola and now I have tried your lines of code as well from the issue #255 but it is still giving me public IP.

Please help here as it is blocking to move further. PFB screenshot FYR.

image

The code written to spin up this server now is

    - name: Create a server
      hetzner.hcloud.hcloud_server:
        api_token: "{{ hcloud_token }}"
        name: my-server
        server_type: cx11
        image: ubuntu-22.04
        location: nbg1
        ## 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: Create a server network and specify the ip address
      hetzner.hcloud.hcloud_server_network:
        network: network1
        server: my-server 
        ip: 10.0.1.10
        state: present
        api_token: "{{ hcloud_token }}"
      delegate_to: localhost
      run_once: true

from hetzner.hcloud.

samiksha1191 avatar samiksha1191 commented on June 16, 2024

Hi @apricote can you please here as well?

from hetzner.hcloud.

jooola avatar jooola commented on June 16, 2024

Hello @samiksha1191

A server without any networking cannot be started. So you can create a server that is stopped, attach your private ip, and start the server afterward. Here is an example:

- name: Create server with a private ip and no public ip
  hosts: localhost
  connection: local
  tasks:
    - name: Create a server
      hetzner.hcloud.hcloud_server:
        name: my-server
        server_type: cx11
        image: ubuntu-22.04
        location: nbg1
        enable_ipv4: false
        enable_ipv6: false
        state: stopped

    - name: Attach private ip to server
      hetzner.hcloud.hcloud_server_network:
        network: network1
        server: my-server
        ip: 10.0.1.10
        state: present

    - name: Start the server
      hetzner.hcloud.hcloud_server:
        name: my-server
        state: started

Also, a few tips for any future bug report:

  • You can wrap your code between triple backticks ` to format it, **_ _** is not a valid Markdown syntax, at least on Github.
  • Make sure to give all information about your problem in the initial report.

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.