Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamic inventory: querying multiple pritunl hosts by criteria #15

Open
dylan-shipwell opened this issue Nov 17, 2021 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@dylan-shipwell
Copy link

Hello,

I was trying to use this module to configure a pritunl_server on dynamic ec2, this worked on first launch!
I think it worked because pritunl assumes if the pritunl_server host_ids field is empty, to use all current hosts, however that host quickly has been terminated and replaced with a new host with the same ip address, and now the pritunl_server definition is broken and tf has no plan to fix it.

I have repaired this by hand for the last few weeks, it becomes broken every time this reprovision happens. The reprovision happens due to a different ami id from a data provider filter, and that change forces the aws_instance to be replaced, and that generates a new unknown pritunl_host hostname. Dealing with it in terraform is an option for this here i think, but I also think there is no way to solve this without a change in this data provider.

Looking into it, at one point here, we have all the host information in memory, which is encouraging, seems like this is really close to being nearly a cosmetic change!

hosts, err := apiClient.GetHosts()

  1. Can we expose the full pritunl_host result set?
    This would enable me to filter it in hcl expressions.
  2. Can we expose the full pritunl host data for each host in the host set?
    Without more data than just hostname and id, I have no way to test which hosts are online and would probably remain stuck.

With a full list of host objects, populated with the full api data from pritunl (example below) I could have filtered the data I needed with a terraform expression and (maybe) been done fixing this dynamic inventory incompatibility.

Are there other ways to work around this limitation? If i could know the generated pritunl_host hostname ahead of committing the hcl, maybe I could explicitly query the data I need. Presently, the data provider has to way I understand to query the list of hostnames that exist, so by definition can't query any pritunl_host data unless I describe them from the pritunl api out of band of this provider, which maybe I could do with a presumptuous curl/wget shell out, would really prefer not to.
maybe I misunderstand: without having the full list of pritunl-generated host names, how can we write a query for a specific hostname? No way to get that string, can only ask for data about a specific string.

Is there some way to request a pritunl server instance use a specific hostname? I looked at the generated /etc/pritunl.conf and there is no setting for server hostname it seems, so i think these strings are just, generated only, so I feel pretty stuck here and confused how this could be used at all.


In case it helps, here is some sample data, with unique values replaced with fake data

{
  "page": 0,
  "page_total": 0,
  "hosts": [
    {
      "id": "0000000000000000000000000000000a",
      "name": "fake-genname-1",
      "hostname": "ip-0-0-0-0",
      "instance_id": null,
      "status": "offline",
      "uptime": null,
      "version": "1.30.2960.4",
      "user_count": 1,
      "users_online": 0,
      "local_networks": [
        "0.0.0.0/0"
      ],
      "public_addr": "0.0.0.0",
      "public_address": null,
      "public_addr6": null,
      "public_address6": null,
      "routed_subnet6": null,
      "routed_subnet6_wg": null,
      "proxy_ndp": null,
      "link_addr": "0.0.0.0",
      "link_address": null,
      "sync_address": null,
      "local_address": null,
      "local_addr": "0.0.0.0",
      "local_address6": null,
      "local_addr6": "::",
      "availability_group": "default"
    },
    {
      "id": "0000000000000000000000000000000b",
      "name": "fake-genname-2",
      "hostname": "ip-0.0.0.0",
      "instance_id": null,
      "status": "online",
      "uptime": 153454,
      "version": "1.30.2960.4",
      "user_count": 0,
      "users_online": 0,
      "local_networks": [
        "0.0.0.0/0"
      ],
      "public_addr": "0.0.0.0",
      "public_address": null,
      "public_addr6": null,
      "public_address6": null,
      "routed_subnet6": null,
      "routed_subnet6_wg": null,
      "proxy_ndp": null,
      "link_addr": "0.0.0.0",
      "link_address": null,
      "sync_address": null,
      "local_address": null,
      "local_addr": "0.0.0.0",
      "local_address6": null,
      "local_addr6": "::",
      "availability_group": "default"
    } 
  ] 
}

for my own needs, I think I need the cross section of status="online" and availability_group="default", and then from that cross section resource.pritunl_server.host_ids = [for i in data.pritunl_host : i.id]

presently, I see no way to get there with the source as is.

Thanks for your attention, I am comfortable proposing some edits to the source with your blessing, so lmk, is there a specific way this case should be dealt with, presumably backwards compatibility is a big deal, and I think the existing provider's hostname requirement makes changing this provider may be complicated to keep backwards compat.

@dylan-shipwell
Copy link
Author

dylan-shipwell commented Nov 17, 2021

looking into work arounds, digging into the pritunl source, shows that there is no hostname setting, but there is a host_id setting which is the actual unique id (as a uuid) of the pritunl_host, this information can be generated in advance of the instance starting, and specifying it can bypass the need to use data pritunl_host since this is the literal value to provide to pritunl_server host_id's as is.

$ grep -oP \\bsettings\\.conf\\S\* -R /usr/lib/pritunl/lib/python3.8/site-packages/pritunl/
$ grep -oP \\bsettings\\.conf\\.host_id -R /usr/lib/pritunl/lib/python3.8/site-packages/pritunl/ 
/usr/lib/pritunl/lib/python3.8/site-packages/pritunl/setup/local.py:settings.conf.host_id

host_id is a valid key to add to /etc/pritunl.conf

beware, the host_id uuid in /etc/pritunl.conf must be not-hypenated, that will break pritunl to place in the conf file

@disc disc added the enhancement New feature or request label Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants