AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-614167

inframan's questions

Martin Hope
motorbass
Asked: 2024-02-08 23:55:56 +0800 CST

Ansible.builtin.wait_for 使用 kerberos 发出奇怪的行为

  • 5

我习惯于使用 Active Directory 服务帐户处理 Windows 环境的许多工作项目,并使用 Hashicorp Vault 进行加密。项目从 Debian 11 服务器启动到许多 Windows Server 目标(主要是 OS Server 2019-2022)

目前,虽然我想将通常从 Debian 服务器启动的 Ansible 项目迁移到 AWX,但我遇到了在两者上都发生的错误。

我的简单测试执行以下操作:

---
# --------------

- name: test-webrequest-win
  hosts: all

  vars_files:
  - vars.yml

  tasks:
  - name: Test win_ping
    ansible.windows.win_ping:

  - name: Test Sleep 10 sec 
    ansible.builtin.wait_for:
      timeout: 10
    delegate_to: localhost

  - name: Test check webrequest
    ansible.builtin.uri:
      url: http://{{inventory_hostname}}:6666/
      return_content: yes
    delegate_to: localhost

我的 vars.yml 配置如下:

---
ansible_user: "{{ vault.ansible_account }}"
ansible_password: "{{ vault.ansible_password }}"

#### Configuration Ansible WinRM
ansible_connection: winrm
ansible_port: 5985
ansible_winrm_transport: kerberos

这是我的问题,正如您在下面看到的那样,win_ping(或实际上每个 Windows 任务)运行良好,但最大的惊喜是关于 ansible.builtin.wait_for 模块

PLAY [test-webrequest-win] ************************************************************************************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************************************************************************************jeudi 08 février 2024  15:55:34 +0100 (0:00:00.014)       0:00:00.014 *********
ok: [10.10.10.10]
ok: [my-server.ansible.com]

TASK [test win_ping] ******************************************************************************************************************************************************************************************jeudi 08 février 2024  15:55:38 +0100 (0:00:04.082)       0:00:04.097 *********
ok: [my-server.ansible.com]
ok: [10.10.10.10]

TASK [Test sleep 10 sec] **************************************************************************************************************************************************************************************jeudi 08 février 2024  15:55:40 +0100 (0:00:02.538)       0:00:06.635 *********
fatal: [10.10.10.10 -> localhost]: UNREACHABLE! => {"changed": false, "msg": "kerberos: authGSSClientStep() failed: (('Unspecified GSS failure.  Minor code may provide more information', 851968), ('Server not found in Kerberos database', -1765328377))", "unreachable": true}
fatal: [my-server.ansible.com -> localhost]: UNREACHABLE! => {"changed": false, "msg": "kerberos: authGSSClientStep() failed: (('Unspecified GSS failure.  Minor code may provide more information', 851968), ('Server not found in Kerberos database', -1765328377))", "unreachable": true}

我对很多主机进行了测试,以检查 AD 部分是否有问题,但收集事实并测试 win_ping 一切正常,无论我使用 FQDN(建议)还是 IP(在我的情况下,这只是测试) )

有什么建议吗?:)

盖尔人

ansible
  • 1 个回答
  • 17 Views
Martin Hope
motorbass
Asked: 2023-09-14 22:29:07 +0800 CST

如何排查 Ansible 模块发送的 API 请求?

  • 7

上下文如下:
以下剧本(为了便于使用而简化为该 stackoverflow 主题的一项任务)获得不同的结果取决于我在哪里启动它。它使用 nutanix.ncp Galaxy 集合(使用版本 1.9.0、1.8.0、1.7.0...进行测试)

调用该ntnx_subnets_info方法来检索 prism 中心实例上现有子网的所有列表,并通过 name 参数进行过滤以仅检索特定 VLAN 的详细信息。

---
- name: test-get-subnet-info
  hosts: localhost

  vars:
    nutanix_host: "{{ XXXXXXX }}"
    nutanix_username: "{{ XXXXXXX }}"
    nutanix_password: "XXXXXXX "

  collections:
    - nutanix.ncp
  module_defaults:
    group/nutanix.ncp.ntnx:
      nutanix_host: "{{ XXXXXXX }}"
      nutanix_username: "{{ XXXXXXX }}"
      nutanix_password: "XXXXXXX "

  tasks:
  - name: Retrieve subnet info
    ntnx_subnets_info:
      filter:
        name: "my-VLAN"

在 Debian 11 服务器上,此任务运行顺利,如下所示在此输入图像描述

而在我的自定义 AWX EE 上(使用 docker 进行测试,然后在 K8s 上进行测试),我收到以下错误,该错误不太明确Failed to convert API response to json
在此输入图像描述

故障排除步骤:

  • 尝试将 nutanix.ncp 集合从 1.9.0 降级到 1.8.0 和 1.7.0 => 仍然是相同的结果(适用于 debian,不适用于 docker)
  • 比较 ansible 版本 => 两个环境都在 ansible core 2.15.4 上运行
  • 比较python版本=> docker镜像环境是3.9.17,debian服务器是3.9.2
  • 从两个环境启动手动curl请求=>一切都在两个环境上运行
  • 使用 -vvvvvv 选项启动 playbook 并比较日志上的差异 => nutanix.ncp 不是那么健谈,我没有收到任何其他错误,正如您在后面的屏幕截图中看到的那样。

问题

  • 有没有办法“分析”Ansible API 请求?就像 Ansible 的wireshark/fiddler 一样?
  • 我怎样才能进一步排除并解决这个问题?因为它在一侧有效,但在其他方面无效,我可能会比较一些东西并希望找到差异?

谢谢

docker
  • 1 个回答
  • 32 Views
Martin Hope
motorbass
Asked: 2023-09-12 22:29:04 +0800 CST

使用 pyopenssl 自定义 EE 映像时出现 AWX 错误 X509

  • 6

我目前正在设置一个托管在 K8s 集群上的 AWX 平台,以获得适合多用户目的的 UI + 功能。

上下文:
我创建了一个推送到 AWX 使用的 Nexus 存储库上的 EE 映像,以便拥有 Ansible 项目所需的所有 ansible Galaxy 集合(nutanix.ncp、community.hashi_vault、community.windows 和 ansible.windows)+ pip 模块(ansible) -pylibssh、hvac、paramiko、pexpect、pykerberos、pywinrm、密码学、pyopenssl)。

EE 镜像创建和推/拉都可以。如果需要,我可以共享requirements.yml和requirements.txt文件。

这是可供参考的execution-environment.yml:

---
version: 1

build_arg_defaults:
  EE_BASE_IMAGE: 'quay.io/ansible/awx-ee:latest'

dependencies:
  galaxy: requirements.yml
  python: requirements.txt

additional_build_steps:
  prepend: |
    RUN python3 -m pip install --upgrade pip
    RUN pip3 install --upgrade pip setuptools
    RUN whoami
    RUN cat /etc/os-release

  append:
  - RUN ls -la /etc

然后,当我使用此 EE 映像在 AWX 上设置项目时,它会因 X509_V_FLAG_CB_ISSUER_CHECK 错误而失败:

{
  "module_stdout": "",
  "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1694504214.889407-61-240849331705059/AnsiballZ_ntnx_subnets_info.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1694504214.889407-61-240849331705059/AnsiballZ_ntnx_subnets_info.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1694504214.889407-61-240849331705059/AnsiballZ_ntnx_subnets_info.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.nutanix.ncp.plugins.modules.ntnx_subnets_info', init_globals=dict(_module_fqn='ansible_collections.nutanix.ncp.plugins.modules.ntnx_subnets_info', _modlib_path=modlib_path),\n  File \"/usr/lib64/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib64/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_ntnx_subnets_info_payload_mpaf5bgi/ansible_ntnx_subnets_info_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_subnets_info.py\", line 188, in <module>\n  File \"<frozen importlib._bootstrap>\", line 991, in _find_and_load\n  File \"<frozen importlib._bootstrap>\", line 975, in _find_and_load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 655, in _load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 618, in _load_backward_compatible\n  File \"<frozen zipimport>\", line 259, in load_module\n  File \"/tmp/ansible_ntnx_subnets_info_payload_mpaf5bgi/ansible_ntnx_subnets_info_payload.zip/ansible_collections/nutanix/ncp/plugins/module_utils/prism/subnets.py\", line 9, in <module>\n  File \"<frozen importlib._bootstrap>\", line 991, in _find_and_load\n  File \"<frozen importlib._bootstrap>\", line 975, in _find_and_load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 655, in _load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 618, in _load_backward_compatible\n  File \"<frozen zipimport>\", line 259, in load_module\n  File \"/tmp/ansible_ntnx_subnets_info_payload_mpaf5bgi/ansible_ntnx_subnets_info_payload.zip/ansible_collections/nutanix/ncp/plugins/module_utils/prism/clusters.py\", line 7, in <module>\n  File \"<frozen importlib._bootstrap>\", line 991, in _find_and_load\n  File \"<frozen importlib._bootstrap>\", line 975, in _find_and_load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 655, in _load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 618, in _load_backward_compatible\n  File \"<frozen zipimport>\", line 259, in load_module\n  File \"/tmp/ansible_ntnx_subnets_info_payload_mpaf5bgi/ansible_ntnx_subnets_info_payload.zip/ansible_collections/nutanix/ncp/plugins/module_utils/prism/prism.py\", line 5, in <module>\n  File \"<frozen importlib._bootstrap>\", line 991, in _find_and_load\n  File \"<frozen importlib._bootstrap>\", line 975, in _find_and_load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 655, in _load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 618, in _load_backward_compatible\n  File \"<frozen zipimport>\", line 259, in load_module\n  File \"/tmp/ansible_ntnx_subnets_info_payload_mpaf5bgi/ansible_ntnx_subnets_info_payload.zip/ansible_collections/nutanix/ncp/plugins/module_utils/entity.py\", line 13, in <module>\n  File \"<frozen importlib._bootstrap>\", line 991, in _find_and_load\n  File \"<frozen importlib._bootstrap>\", line 975, in _find_and_load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 655, in _load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 618, in _load_backward_compatible\n  File \"<frozen zipimport>\", line 259, in load_module\n  File \"/tmp/ansible_ntnx_subnets_info_payload_mpaf5bgi/ansible_ntnx_subnets_info_payload.zip/ansible/module_utils/urls.py\", line 115, in <module>\n  File \"/usr/lib/python3.8/site-packages/urllib3/contrib/pyopenssl.py\", line 46, in <module>\n    import OpenSSL.SSL\n  File \"/usr/local/lib/python3.8/site-packages/OpenSSL/__init__.py\", line 8, in <module>\n    from OpenSSL import crypto, SSL\n  File \"/usr/local/lib/python3.8/site-packages/OpenSSL/crypto.py\", line 1517, in <module>\n    class X509StoreFlags(object):\n  File \"/usr/local/lib/python3.8/site-packages/OpenSSL/crypto.py\", line 1537, in X509StoreFlags\n    CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK\nAttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'\n",
  "exception": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1694504214.889407-61-240849331705059/AnsiballZ_ntnx_subnets_info.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1694504214.889407-61-240849331705059/AnsiballZ_ntnx_subnets_info.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1694504214.889407-61-240849331705059/AnsiballZ_ntnx_subnets_info.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.nutanix.ncp.plugins.modules.ntnx_subnets_info', init_globals=dict(_module_fqn='ansible_collections.nutanix.ncp.plugins.modules.ntnx_subnets_info', _modlib_path=modlib_path),\n  File \"/usr/lib64/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib64/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_ntnx_subnets_info_payload_mpaf5bgi/ansible_ntnx_subnets_info_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_subnets_info.py\", line 188, in <module>\n  File \"<frozen importlib._bootstrap>\", line 991, in _find_and_load\n  File \"<frozen importlib._bootstrap>\", line 975, in _find_and_load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 655, in _load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 618, in _load_backward_compatible\n  File \"<frozen zipimport>\", line 259, in load_module\n  File \"/tmp/ansible_ntnx_subnets_info_payload_mpaf5bgi/ansible_ntnx_subnets_info_payload.zip/ansible_collections/nutanix/ncp/plugins/module_utils/prism/subnets.py\", line 9, in <module>\n  File \"<frozen importlib._bootstrap>\", line 991, in _find_and_load\n  File \"<frozen importlib._bootstrap>\", line 975, in _find_and_load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 655, in _load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 618, in _load_backward_compatible\n  File \"<frozen zipimport>\", line 259, in load_module\n  File \"/tmp/ansible_ntnx_subnets_info_payload_mpaf5bgi/ansible_ntnx_subnets_info_payload.zip/ansible_collections/nutanix/ncp/plugins/module_utils/prism/clusters.py\", line 7, in <module>\n  File \"<frozen importlib._bootstrap>\", line 991, in _find_and_load\n  File \"<frozen importlib._bootstrap>\", line 975, in _find_and_load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 655, in _load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 618, in _load_backward_compatible\n  File \"<frozen zipimport>\", line 259, in load_module\n  File \"/tmp/ansible_ntnx_subnets_info_payload_mpaf5bgi/ansible_ntnx_subnets_info_payload.zip/ansible_collections/nutanix/ncp/plugins/module_utils/prism/prism.py\", line 5, in <module>\n  File \"<frozen importlib._bootstrap>\", line 991, in _find_and_load\n  File \"<frozen importlib._bootstrap>\", line 975, in _find_and_load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 655, in _load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 618, in _load_backward_compatible\n  File \"<frozen zipimport>\", line 259, in load_module\n  File \"/tmp/ansible_ntnx_subnets_info_payload_mpaf5bgi/ansible_ntnx_subnets_info_payload.zip/ansible_collections/nutanix/ncp/plugins/module_utils/entity.py\", line 13, in <module>\n  File \"<frozen importlib._bootstrap>\", line 991, in _find_and_load\n  File \"<frozen importlib._bootstrap>\", line 975, in _find_and_load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 655, in _load_unlocked\n  File \"<frozen importlib._bootstrap>\", line 618, in _load_backward_compatible\n  File \"<frozen zipimport>\", line 259, in load_module\n  File \"/tmp/ansible_ntnx_subnets_info_payload_mpaf5bgi/ansible_ntnx_subnets_info_payload.zip/ansible/module_utils/urls.py\", line 115, in <module>\n  File \"/usr/lib/python3.8/site-packages/urllib3/contrib/pyopenssl.py\", line 46, in <module>\n    import OpenSSL.SSL\n  File \"/usr/local/lib/python3.8/site-packages/OpenSSL/__init__.py\", line 8, in <module>\n    from OpenSSL import crypto, SSL\n  File \"/usr/local/lib/python3.8/site-packages/OpenSSL/crypto.py\", line 1517, in <module>\n    class X509StoreFlags(object):\n  File \"/usr/local/lib/python3.8/site-packages/OpenSSL/crypto.py\", line 1537, in X509StoreFlags\n    CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK\nAttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'\n",
  "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
  "rc": 1,
  "_ansible_no_log": false,
  "changed": false
}

测试: 我尝试了以下测试来尝试解决它:

  • 获取最新版本的密码学和 pyopenssl
  • 将加密技术降级至 36.0.2/37.0.0,将 pyopenssl 版本降级至 22.0.0,如某些 stackoverflow 帖子中所示
  • 在镜像创建中的additional_build_steps > prepend块上运行pip3升级

另外,还有一些我不明白的事情:
我看到错误日志提到了该文件\"/usr/lib/python3.8/site-packages/urllib3/contrib/pyopenssl.py 但是当我运行 shell docker 映像时没有 /usr/lib/python3.8 而是 python3.9 文件夹。

问题: 当我登录到 AWX pod 时,我发现只有 awx-operator-controller-manager pod 获得了该路径 python3.8 路径。那么,在尝试运行项目时,AWX pods/EE 映像之间的关系是什么?

关于 pyopenssl,我还可以测试哪些其他测试/解决方案?

谢谢 !

ansible
  • 1 个回答
  • 29 Views
Martin Hope
motorbass
Asked: 2023-06-29 23:40:06 +0800 CST

使用 Powershell 和 Nutanix API 更新 JSON 有效负载

  • 6

我目前正在编写一个允许更新 Nutanix VM 类别的脚本。类别格式为键:值,虚拟机可以没有类别,可以有 1 个或多个类别。

执行此操作的过程非常简单:首先,我创建一个请求来获取现有 VM 信息 (GET)(然后检索其 UUID)。

第二次,我创建另一个请求,通过使用之前检索到的 UUID 来更新现有 VM (PUT),并更改我需要更改的内容(更新类别,但应该添加磁盘、网卡等...)

目前,获取虚拟机的请求很简单并且工作顺利,但当我需要使用第二个请求来更新虚拟机时遇到了问题。我们到了 :

用于此请求的有效负载在 JSON 中如下所示

{
  "spec": {
    "cluster_reference": {
      "kind": "cluster",
      "name": "my_cluster",
      "uuid": "0004f63d-6664-35ce-0126-88e9a456d3fc"
    },
    "name": "test-vm",
    "resources": {
      "num_threads_per_core": 1,
      "vnuma_config": {
        "num_vnuma_nodes": 0
      },
      "serial_port_list": [],
      "nic_list": [
        {
          "nic_type": "NORMAL_NIC",
          "uuid": "334e302a-db6a-48fb-b138-c3e3b2f1d8f6",
          "ip_endpoint_list": [
            {
              "ip": "10.230.172.84",
              "type": "ASSIGNED"
            }
          ],
          "vlan_mode": "ACCESS",
          "mac_address": "50:6b:8d:c5:6c:f0",
          "subnet_reference": {
            "kind": "subnet",
            "name": "vlanXXX",
            "uuid": "6de66666-05ec-46ac-6666-aea60e8e831f"
          },
          "is_connected": true,
          "trunked_vlan_list": []
        }
      ],
      "num_vcpus_per_socket": 1,
      "num_sockets": 1,
      "gpu_list": [],
      "is_agent_vm": false,
      "memory_size_mib": 4096,
      "boot_config": {
        "boot_device_order_list": [
          "CDROM",
          "DISK",
          "NETWORK"
        ],
        "boot_type": "LEGACY"
      },
      "hardware_clock_timezone": "UTC",
      "power_state_mechanism": {
        "guest_transition_config": {
          "should_fail_on_script_failure": false,
          "enable_script_exec": false
        },
        "mechanism": "HARD"
      },
      "power_state": "ON",
      "machine_type": "PC",
      "vga_console_enabled": true,
      "memory_overcommit_enabled": false,
      "disk_list": [
        {
          "uuid": "6f6ad0ba-5b81-487d-8c7b-6c5249a51f4b",
          "disk_size_bytes": 48318382080,
          "storage_config": {
            "storage_container_reference": {
              "kind": "storage_container",
              "uuid": "13611573-1364-4065-a03d-67a7da51c14d",
              "name": "SelfServiceContainer"
            }
          },
          "device_properties": {
            "disk_address": {
              "device_index": 0,
              "adapter_type": "SCSI"
            },
            "device_type": "DISK"
          },
          "data_source_reference": {
            "kind": "image",
            "uuid": "50a186ef-2538-43f3-9d6c-9150dd464ad7"
          },
          "disk_size_mib": 46080
        }
      ]
    },
    "description": "test sync categorie"
  },
  "api_version": "3.1",
  "metadata": {
    "last_update_time": "2023-06-29T14:25:48Z",
    "kind": "vm",
    "uuid": "6e1b8781-8a2a-4830-a15a-0af30daccf89",
    "project_reference": {
      "kind": "project",
      "name": "_internal",
      "uuid": "706f34c2-98be-4034-92e2-859be84040f3"
    },
    "creation_time": "2023-06-29T14:25:48Z",
    "spec_version": 3,
    "categories_mapping": {
      "AppType": [
        "Exchange"
      ],
      "AppTier": [
        "Default"
      ]
    },
    "entity_version": "2",
    "owner_reference": {
      "kind": "user",
      "name": "OWNER",
      "uuid": "6caba9b0-00a9-57ea-8ba0-10162c0b1dd4"
    },
    "categories": {
      "AppType": "Exchange",
      "AppTier": "Default"
    }
  }
}

在 Powershell 中转换后看起来像这样(注意:我们只对元数据感兴趣,你会明白为什么)

PS C:\Users\XXX> $payload.metadata

last_update_time   : 29/06/2023 14:25:48
kind               : vm
uuid               : 6e1b8781-8a2a-4830-a15a-0af30daccf89
project_reference  : @{kind=project; name=_internal; uuid=706f34c2-98be-4034-92e2-859be84040f3}
creation_time      : 29/06/2023 14:25:48
spec_version       : 3
categories_mapping : @{AppType=System.Object[]; AppTier=System.Object[]}
entity_version     : 2
owner_reference    : @{kind=user; name=owner; uuid=6caba9b0-00a9-57ea-8ba0-10162c0b1dd4}
categories         : @{AppType=Exchange; AppTier=Default}


PS C:\Users\XXX> $payload.metadata.categories

AppType  AppTier
-------  -------
Exchange Default

正如你从PS的角度看到的,$payload它的属性是PSCustomObject,所以我不能使用像.Add(), .Remove()etc这样的方法...都不是+=

目前,我可以使用原始 JSON 有效负载手动更新虚拟机,并以 JSON 格式手动添加类别并通过 Postman 进行测试。效果很好。

问题是,正如您可能已经理解的那样,我必须保留 GET 方法中的所有原始有效负载 > 实现添加新类别 > 发送 PUT 请求以完全更新它而不会出现错误。

我的问题是:从 PS 的角度来看,如何轻松创建和添加新的 key:value 对象,并通过保留现有对象将其正确添加到类别中?(=如何在“categories”中插入新值:{“AppType”:“Exchange”,“AppTier”:“Default”})

PS:作为参考,这里是我在 PS 中用于 GET/PUT 的 Web 请求。PUT 请求正在工作,但除了 PUT 与原始值相同的值之外什么都不做:

#### -- HEADER
$Header_Prism = @{
    'Accept' = 'application/json'
    'Content-Type' = 'application/json'
    'Authorization' = $basicAuthValue
}

#### --- GET VM
$get_vm = Invoke-RestMethod -Uri "https://mynutanix.net/vms/6e1b8781-6666-4830-a15a-0af30daccf89"  `
-Method GET `
-Headers $Header_Prism


### --- PUT VM
$payload = $get_vm | select spec,api_version,metadata | convertTo-Json -depth 100


$put_vm = Invoke-RestMethod -Uri "https://mynutanix.net/vms/6e1b8781-6666-4830-a15a-0af30daccf89"  `
-Method PUT `
-Headers $Header_Prism `
-Body $payload

powershell
  • 1 个回答
  • 28 Views
Martin Hope
motorbass
Asked: 2023-06-01 21:41:15 +0800 CST

sfdisk 和 fdisk on LVM disk extend 的区别

  • 6

为了在从模板克隆的 Debian 11 VM 上半自动化 LVM 分区扩展,与sfdisk交互式fdisk.

  1. 这是原始分区
root# sudo fdisk /dev/sda

Commande (m pour l'aide) : p
Disque /dev/sda : 45 GiB, 48318382080 octets, 94371840 secteurs
Modèle de disque : VDISK
Unités : secteur de 1 × 512 = 512 octets
Taille de secteur (logique / physique) : 512 octets / 4096 octets
taille d'E/S (minimale / optimale) : 4096 octets / 1048576 octets
Type d'étiquette de disque : dos
Identifiant de disque : 0x919d40af

Périphérique Amorçage    Début      Fin Secteurs Taille Id Type
/dev/sda1    *            2048  2000895  1998848   976M 83 Linux
/dev/sda2              2000896 86962175 84961280  40,5G 8e LVM Linux
/dev/sda3             86964222 94369791  7405570   3,5G  5 Étendue
/dev/sda5             86964224 94369791  7405568   3,5G 83 Linux
  1. 我通过 fdisk 执行以下任务以扩展 LVM 的 VG:注意:未使用 sda3 和 sda5,这就是我删除它们的原因。
  • 删除分区 5 : "d", 5
  • 删除分区 3 : "d", 3
  • 删除分区 2 : "d", 2
  • 使用默认开始/结束扇区创建新的扩展部分 2,类型为 LVM:“n”、“e”、“2”、“t”、“lvm”

结果是:

Commande (m pour l'aide) : p
Disque /dev/sda : 45 GiB, 48318382080 octets, 94371840 secteurs
Modèle de disque : VDISK
Unités : secteur de 1 × 512 = 512 octets
Taille de secteur (logique / physique) : 512 octets / 4096 octets
taille d'E/S (minimale / optimale) : 4096 octets / 1048576 octets
Type d'étiquette de disque : dos
Identifiant de disque : 0x919d40af

Périphérique Amorçage   Début      Fin Secteurs Taille Id Type
/dev/sda1    *           2048  2000895  1998848   976M 83 Linux
/dev/sda2             2000896 94371839 92370944    44G 8e LVM Linux

接下来,在 VM 磁盘从 45=>60GB 增长后,我可以使用以下命令刷新 sda2sudo pvresize /dev/sda2

然后,扩展我的 LVM 的 VGssudo lvextend -L +5G /dev/vg/my_vg_name

最后,调整文件系统大小sudo resize2fs /dev/vg/my_vg_name 并成功重启。

  1. 我想编写这些操作的脚本(肯定需要人工验证)所以我的第一个想法是使用sfdisk. 在将命令放入脚本之前,我手动测试它们,所以我会这样做:
  • 删除分区 5:sudo sfdisk /dev/sda 5 --delete --force --lock;
  • 删除分区 3:sudo sfdisk /dev/sda 3 --delete --force --lock;
  • 删除分区 2:sudo sfdisk /dev/sda 2 --delete --force --lock;
  • 使用默认开始/结束扇区创建新的扩展部分 2,类型为 LVM:
sudo sfdisk /dev/sda 2 --force --lock << EOF
,,V
write
EOF  

结果似乎不错,sda2 大小从 45 增加到 ~60GB:

Disque /dev/sda : 60 GiB, 64424509440 octets, 125829120 secteurs
Modèle de disque : VDISK
Unités : secteur de 1 × 512 = 512 octets
Taille de secteur (logique / physique) : 512 octets / 4096 octets
taille d'E/S (minimale / optimale) : 4096 octets / 1048576 octets
Type d'étiquette de disque : dos
Identifiant de disque : 0x919d40af

Périphérique Amorçage   Début       Fin  Secteurs Taille Id Type
/dev/sda1    *           2048   2000895   1998848   976M 83 Linux
/dev/sda2             2000896 125829119 123828224    59G 8e LVM Linux

现在让我们刷新 sda2,然后扩展一个 VG,它变坏了:

root# sudo pvresize /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

root# sudo lvextend -L +5G /dev/vg/var
  Insufficient free space: 1280 extents needed, but only 0 available

似乎分区表不是最新的 sfdisk 而它是 fdisk。

这是 sfdisk 的“正常”行为还是我错过了什么?

此外,如果您有更简单的想法或任何建议,请随时告诉它是否具有建设性。

debian
  • 1 个回答
  • 35 Views
Martin Hope
motorbass
Asked: 2023-04-04 19:43:03 +0800 CST

如何解析和过滤 Ansible 上的字典值?

  • 7

我目前正在编写一本在 Nutanix Prism Central 上创建 K8s 集群的剧本。一切运行顺利,但当一个或多个集群上存在 VLAN 时,我遇到了一个问题。

在我的例子中,一个 VLAN 由它的名称和它的 UUID 表示(这个可以在 entities[] 内的每个索引上被检索到元数据中)。

由于一个 VLAN 可能存在多次(因为它是在不同的集群上配置的),这意味着 UUID 值在元数据 {} 上可能不同,但它的名称永远不会。下面是我得到的结果:

ok: [localhost] => {
    "msg": {
        "changed": false,
        "error": null,
        "failed": false,
        "response": {
            "api_version": "3.1",
            "entities": [
                {
                    "metadata": {
                        "categories": {},
                        "categories_mapping": {},
                        "creation_time": "2023-03-08T10:11:44Z",
                        "kind": "subnet",
                        "last_update_time": "2023-03-08T10:11:44Z",
                        "spec_hash": "00000000000000000000000000000000000000000000000000",
                        "spec_version": 0,
                        "uuid": "aaaa-bbbb-cccc-dddddd"
                    },
                    "spec": {
                        "cluster_reference": {
                            "kind": "cluster",
                            "name": "Cluster02",
                            "uuid": "123123-123123-123123"
                        },
                        "name": "MY-VLAN",
                        "resources": {
                            "subnet_type": "VLAN",
                            "virtual_switch_uuid": "321-321-321-321-321",
                            "vlan_id": 66,
                            "vswitch_name": "br0"
                        }
                    },
                    "status": {
                        "cluster_reference": {
                            "kind": "cluster",
                            "name": "Cluster02",
                            "uuid": "123123-123123-123123"
                        },
                        "name": "MY-VLAN",
                        "resources": {
                            "ip_usage_stats": {
                                "num_macs": 0
                            },
                            "subnet_type": "VLAN",
                            "virtual_switch_uuid": "321-321-321-321-321",
                            "vlan_id": 66,
                            "vswitch_name": "br0"
                        },
                        "state": "COMPLETE"
                    }
                },
                {
                    "metadata": {
                        "categories": {},
                        "categories_mapping": {},
                        "creation_time": "2023-03-08T10:11:42Z",
                        "kind": "subnet",
                        "last_update_time": "2023-03-08T10:11:42Z",
                        "spec_hash": "00000000000000000000000000000000000000000000000000",
                        "spec_version": 0,
                        "uuid": "999-999-999-999-999"
                    },
                    "spec": {
                        "cluster_reference": {
                            "kind": "cluster",
                            "name": "Cluster01",
                            "uuid": "0005f64b-e395-8cc2-16af-88e9a456e31a"
                        },
                        "name": "MY-VLAN",
                        "resources": {
                            "subnet_type": "VLAN",
                            "virtual_switch_uuid": "d4f9ed4f-72c3-4ad0-8223-070fba6a9aea",
                            "vlan_id": 66,
                            "vswitch_name": "br0"
                        }
                    },
                    "status": {
                        "cluster_reference": {
                            "kind": "cluster",
                            "name": "Cluster01",
                            "uuid": "0005f64b-e395-8cc2-16af-88e9a456e31a"
                        },
                        "name": "MY-VLAN",
                        "resources": {
                            "ip_usage_stats": {
                                "num_macs": 0
                            },
                            "subnet_type": "VLAN",
                            "virtual_switch_uuid": "d4f9ed4f-72c3-4ad0-8223-070fba6a9aea",
                            "vlan_id": 66,
                            "vswitch_name": "br0"
                        },
                        "state": "COMPLETE"
                    }
                }
        }
    }
}

目前,如果我通过执行以下任务知道索引号,我知道如何手动检索 UUID:

  - name: Get Network
    ntnx_subnets_info:
      filter:
        #subnet_type: "VLAN"
        name: "MY-VLAN"
      kind: subnet
    register: result
    ignore_errors: True

  - name: output of identified network
    debug:
      msg: '{{ result.response.entities[0].metadata.uuid }}'

但我目前无法在专用集群上获取 UUID。例如,如果我需要从 Cluster01 检索 vlan uuid,我必须选择“{{ result.response.entities[1].metadata.uuid }}”

有人知道是否可以根据嵌套属性(在我的例子中是 spec.cluster_reference.name)动态检索值吗?

多谢 !

ansible
  • 1 个回答
  • 70 Views
Martin Hope
motorbass
Asked: 2022-12-30 08:04:56 +0800 CST

关于 Debian 11 自动化安装的建议

  • 5

我目前正在尝试通过 Packer for Nutanix 环境自动创建 Debian 11 模板,并且需要一些关于预置/自动安装 Debian 的建议。

首先,在阅读了这本圣经https://www.debian.org/releases/stable/amd64/apbs02.fr.html之后,我开始使用 preseed.cfg 文件。我从 Debian 提供的 preseed.cfg 文件开始,然后调整一些内容以满足我的需要。最后,我使用命令 => 验证语法debconf-set-selections -c preseed.cfg一切正常。

现在,我看到有 3 种不同的方法来使用 preseed.cfg :

  • 通过 initrd :对我来说似乎很难并且没有找到简单的教程/文档
  • 通过网络:由于某些防火墙限制,目前不是一个选项
  • 通过文件:目前似乎是最简单和最好的选择

当 Packer 开始创建 VM 时,它会将 debian ISO 作为 CD-ROM 加载到第一个位置,并在第二个位置加载一个空虚拟磁盘。我告诉打包程序将我的 preseed.cfg 脚本加载为 cd-rom,因此从管理程序的角度来看,第二个 cd-rom 驱动器安装在第三个位置。

但是,在这种情况下,VM 在 ISO(cd-rom 第一位置)上启动,它不会挂载具有 preseed.cfg 文件的第二个 cd-rom 驱动器,除非我转到 debian 控制台,否则我无法访问它然后安装第二个驱动器。

我看到一个关于将 preseed.cfg 上传到我原来的 debian.iso 文件夹并像这样修改 /isolinux/txt.cfg 文件的论坛(然后用 OSCDIMG 重新创建 iso):

label install
    menu label ^Install
    kernel /install.amd/vmlinuz
    append vga=788 initrd=/install.amd/initrd.gz preseed/file=/cdrom/preseed/preseed.cfg --- quiet

我的问题是:这样做公平吗?有什么我错过的或更容易让它工作的东西吗?

编辑:我尝试了 initrd 方法,唯一剩下的就是我必须手动选择自动安装。如何摆脱这个动作?

编辑 2:02-01-2023

  • 我尝试了 2 个不同的东西,第一个是在 isolinux/txt.cfg 中有这一行 append auto=true priority=critical vga=788 initrd=/install.amd/initrd.gz preseed/file=/cdrom/preseed.cfg --- quiet=> NOK,它仍然在启动菜单上启动(但是如果我手动选择自动安装就可以了,所以这意味着 preseed.cfg 工作得很好)
  • 第二,prompt 1 timeout 1在 isolinux.cfg 中进行测试 => 直接手动选择语言...

EDIT3: 03-01-2023 这是我使用的 preseed.cfg:

# SETUP AUTO MODE
d-i auto-install/enable boolean true
d-i debconf/priority select critical
# LANGUAGE & KEYMAP
d-i debian-installer/locale string fr_FR
d-i keyboard-configuration/xkb-keymap select fr(latin9)
# NETWORK
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string template-debian-11-x64
d-i netcfg/get_domain string my_domain.net
d-i netcfg/hostname string template-debian-11-x64
# MIRRORS
d-i mirror/http/hostname string  http://deb.debian.org/debian/ 
d-i mirror/http/hostname string http://security.debian.org/debian-security 
# ACCOUNTS
d-i passwd/root-password password mypassword!
d-i passwd/root-password-again password mypassword!
d-i passwd/user-fullname string user
d-i passwd/username string user
d-i passwd/user-password password mypassword!
d-i passwd/user-password-again password mypassword!
d-i passwd/user-uid string 1010
d-i passwd/user-default-groups string si audio cdrom video
# LVM PART
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string lvm
d-i partman-auto-lvm/guided_size string 95%
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto/choose_recipe select multi
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
#APT
d-i apt-setup/cdrom/set-first boolean false
tasksel tasksel/first multiselect standard, ssh-server
# GRUB
d-i grub-installer/bootdev string /dev/sda
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
#FINAL
d-i finish-install/reboot_in_progress note

非常感谢

盖尔语

debian
  • 2 个回答
  • 112 Views
Martin Hope
inframan
Asked: 2022-10-07 22:58:09 +0800 CST

Ansible 在使用查找函数进行模板化时发生未处理的异常

  • 0

我目前正在构建一个剧本来测试是否存在一些 conf 文件,然后检查内容。文件如下

  • /etc/resolv.conf - 然后检查名称服务器是否配置正确
  • /etc/systemd/timesyncd.conf - 检查是否已配置某些内容
  • /etc/ntp.conf - 还要检查是否已配置某些内容

.yml 代码如下,您可以看到每次检查的任务都是相同的,如果需要,只需重新配置文件路径和正则表达式部分。

  tasks:
    # RESOLV.CONF
    - name: Check if resolv.conf exist
      stat:
        path: /etc/resolv.conf
      register: resolv_conf

    - name: Retrieve nameservers
      debug:
        msg: "{{ contents }}"
      vars:
        contents: "{{ lookup('file', '/etc/resolv.conf') | regex_findall('\\s*nameserver\\s*(.*)') }}"
      when: resolv_conf.stat.exists == True

    # NTP.CONF
    - name: check if ntp.conf exists
      stat:
        path: /etc/ntp.conf
      register: ntp_conf

    - name: retrieve ntp conf server content
      debug:
        msg: "{{ contents }}"
      vars:
        contents: "{{ lookup('file', '/etc/ntp.conf') | regex_search('^server.*') }}"
      when: ntp_conf.stat.exists == True

    # TIMESYNC.CONF
    - name: check if timesyncd
      stat:
        path: /etc/systemd/timesyncd.conf 
      register: timesyncd_conf 

    - name: Affiche le contenu de timesyncd.conf s'il est configure
      debug:
        msg: "{{ contents }}"
      vars:
        contents: "{{ lookup('file', '/etc/systemd/timesyncd.conf') | regex_search('^NTP=.*') }}"
      when: timesyncd_conf.stat.exists == True

除了关于 NTP.CONF 检查失败并显示以下内容的任务外,这些任务运行良好:

vendredi 07 octobre 2022  08:28:07 +0200 (0:00:00.509)       0:00:05.115 ******
[WARNING]: Unable to find '/etc/ntp.conf' in expected paths (use -vvvvv to see paths)
fatal: [my_server]: FAILED! => {"msg": "An unhandled exception occurred while templating '{{ lookup('file', '/etc/ntp.conf') | regex_search('^server.*') }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while running the lookup plugin 'file'. Error was a <class 'ansible.errors.AnsibleError'>, original message: could not locate file in lookup: /etc/ntp.conf. could not locate file in lookup: /etc/ntp.conf"}

我不明白为什么它会失败,因为我使用相同的功能,用户和文件获得了相同的权限,在 /etc/. 此外,我很快尝试对“cat”做同样的事情,它有效:

 - name: check ntp.conf content  
      command: "cat /etc/ntp.conf"
      register: ntp_conf_contenu
    - debug:
        msg:
        - " {{ ntp_conf_contenu  | regex_findall ('server') }}"

你知道它为什么失败吗?

非常感谢 !

ansible
  • 1 个回答
  • 51 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve