You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Ansible Playbook以本地运行community.general.pritunl_user_info模块

问题描述

我正在自动化Pritunl VPN的运维管理,使用community.general.pritunl_user_info模块编写了测试Playbook,希望仅通过本地控制器调用API获取数据,无需部署到远程主机,但执行时失败,报错HTTP 404。

测试Playbook

- name: "pritunl test"
  hosts: localhost
  gather_facts: no
  connection: local
  become: no
  
  tasks:
  - name: "list pritunl users"
    community.general.pritunl_user_info:
     pritunl_url: https://xxxxx/
     pritunl_api_token: yyyyyy
     pritunl_api_secret: zzzzzz
     organization: xxyyzz

报错信息

[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
redirecting (type: modules) community.general.pritunl_user_info to community.general.net_tools.pritunl.pritunl_user_info
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: pritunl_users.yml *****************************************************************************************************************************
1 plays in pritunl_users.yml

PLAY [pritunl test] *************************************************************************************************************************************
META: ran handlers

TASK [list pritunl users] *******************************************************************************************************************************
task path: /home/.../pritunl_users.yml:8
redirecting (type: modules) community.general.pritunl_user_info to community.general.net_tools.pritunl.pritunl_user_info
redirecting (type: modules) community.general.pritunl_user_info to community.general.net_tools.pritunl.pritunl_user_info
fatal: [localhost]: FAILED! => {"changed": false, "msg": "HTTP Error 404: Not Found"}

PLAY RECAP **********************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
解决步骤

你的Playbook本地执行的配置本身是有效的,hosts: localhost、connection: local已经确保在本地运行,报错404的核心问题是API调用路径或参数错误,按以下步骤修正:

  1. 修正pritunl_url格式
    Pritunl的API根路径为/api,URL不能只写https://xxxxx/,必须补充完整路径:

    pritunl_url: https://xxxxx/api/
    

    注意末尾斜杠不能省略,否则模块拼接API路径时会出错。

  2. 验证organization参数的正确性
    模块的organization参数需要填写组织ID,而非显示名称。你可以通过Pritunl Web界面获取:进入组织详情页,URL中/organization/后的字符串即为组织ID(例如https://xxxxx/organization/abc123里的abc123),填错会触发404错误。

  3. 确认API权限与网络可达性

    • 检查API令牌和密钥是否拥有读取用户信息的权限
    • 确保本地控制器能正常访问Pritunl的API地址,无防火墙或代理拦截
  4. 可选:消除inventory警告
    若要去掉开头的inventory警告,可在Playbook同目录创建极简inventory文件,内容为:

    localhost ansible_connection=local
    

    执行时加上-i inventory参数,或直接在Playbook中指定:

    - name: "pritunl test"
      hosts: localhost
      inventory: localhost
      gather_facts: no
      connection: local
      become: no
    

内容的提问来源于stack exchange,提问作者Eric

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 19:03:37