Open varuzam opened 2 years ago
Hi, we have a similar problem. Our goal is to create a VM that only has a static IP in a private network and no public IP.
hcloud_server_network
module after creating a server with a public IPprivate_networks
key in hcloud_server
does not support a static IP, we tried not using it. This leads to invalid input: server must be attached to at least one of: primary_ipv4, primary_ipv6, private_network
private_networks
and then trying to change the IP to static using hcloud_server_network
afterwards does not do anything (unchanged / OK in ansible)You can find the detailed tasks in our role here.
Possible solutions:
hcloud_server_network
module.private_network
as mentioned above in the original postHi, I also have a similar problem. I am using Ansible to create a server in the Hetzner cloud. My aim is to integrate the new server into a private network that I have previously created. The server should not be accessible via the internet, so I have disabled ipv4 and ipv6. Rather, I'd like to access the server by connecting via OpenVPN to the private network 'ipfire' and connect by use of ssh from there.
Same for me. The only workaround for us currently is to create a server with public ip and manually add it to a network with a static IP, then disable the public ip again.
This issue has been marked as stale because it has not had recent activity. The bot will close the issue if no further action occurs.
Up
While I understand implementing this in the server module might make your lives easier, what do you folks think about this:
I am not sure If we want to continue packing new feature in the server module, which is already really big.
Creating the server in stopped state works for my use case, thanks for the tip @jooola! The documentation could include this as an example; it's not easy to find out that this is possible.
@jooola Your code is OK for one time run. But speaking about big production infra when a playbook is run several time it is not desirable to stop and start production servers each time
@jooola is on vacation this week, but will be back on Monday.
@varuzam maybe the [check_mode
can help you there. You can run the hetzner.hcloud.server_network
in check mode first, to see if any changes would be made and only shutdown the server if needed. Some pseudo code:
tasks:
- name: Check if private IP needs to be changed
hetzner.hcloud.server_network:
network: my-network
server: "{{ name }}"
ip: "{{ private_ip }}"
state: present
check_mode: true
register: ip_changes
- name: Update private IP
when: ip_changes is changed # Or `ip_changes.changed == true`
block:
- name: Shutdown Server
# ...
- name: Update IP
# ...
- name: Start Server
# ...
Your code is OK for one time run. But speaking about big production infra when a playbook is run several time it is not desirable to stop and start production servers each time.
Could you explain what your use case is ?
If your server is already running, it should already have some IP assigned. Then adding or updating a private IP should be done using the server_network
module. Updating a private IP is not yet doable using the server_network
but I'd be happy to implement it if this solves your problem (I'll check if this is actually doable). But maybe your use case will help me better understand the problem.
EDIT: I just checked, and we cannot update a private IP, as we cannot assign multiple IP on the same network, and therefor have to shut down the server before removing and adding a new IP. We might be able to implement this by shutting down the server in the server_network
module, but only when a force
flag is set to true.
SUMMARY
A while ago support for private network was added https://github.com/ansible-collections/hetzner.hcloud/commit/ad8958a2ad3ff060df01a275a594419ed100c27e But there is no way to set static private ip. It would be nice to have this ability.
ISSUE TYPE
COMPONENT NAME
hetzner.hcloud.server module
ADDITIONAL INFORMATION