【问题标题】:Facing problems with ansible playbooks面对 ansible playbook 的问题
【发布时间】:2022-01-01 14:23:54
【问题描述】:

我正在尝试学习 ansible 并开始配置。在完成所有配置之后,例如在 group_vars 和我的 makefile 中指定 sshkey 的路径。我仍然不知何故无法完成任务。

运行 ansible playbook 时出错

运行ansible-playbook provision_instances.yml 时出现以下错误。我似乎拒绝连接到本地主机。

我在尝试 ansible-playbook provision_instances.yml 之后运行了 make add-ssh

   `TASK [security_groups : Create Network Security Group]********************************************************************************************`


    The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_azure_rm_securitygroup_payload_vkggeut2/ansible_azure_rm_securitygroup_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py", line 249, in <module>
    from azure.mgmt.privatedns import PrivateDnsManagementClient
ModuleNotFoundError: No module named 'azure.mgmt.privatedns'
failed: [localhost -> 127.0.0.1] (item={'name': 'database', 'port_rules': [{'name': 'SSH', 'protocol': 'Tcp', 'destination_port_range': 22, 'access': 'Allow', 'priority': 1001, 'direction': 'Inbound', 'source_address_prefix': '0.0.0.0/0'}, {'name': 'MYSQL', 'protocol': 'Tcp', 'destination_port_range': 3306, 'access': 'Allow', 'priority': 1002, 'direction': 'Inbound', 'source_address_prefix': '0.0.0.0/0'}]}) => {
    "ansible_loop_var": "group",
    "changed": false,
    "group": {
        "name": "database",
        "port_rules": [
            {
                "access": "Allow",
                "destination_port_range": 22,
                "direction": "Inbound",
                "name": "SSH",
                "priority": 1001,
                "protocol": "Tcp",
                "source_address_prefix": "0.0.0.0/0"
            },
            {
                "access": "Allow",
                "destination_port_range": 3306,
                "direction": "Inbound",
                "name": "MYSQL",
                "priority": 1002,
                "protocol": "Tcp",
                "source_address_prefix": "0.0.0.0/0"
            }
        ]
    },
    "invocation": {
        "module_args": {
            "ad_user": null,
            "adfs_authority_url": null,
            "api_profile": "latest",
            "append_tags": true,
            "auth_source": "auto",
            "cert_validation_mode": null,
            "client_id": null,
            "cloud_environment": "AzureCloud",
            "default_rules": null,
            "location": null,
            "log_mode": null,
            "log_path": null,
            "name": "database-sg",
            "password": null,
            "profile": null,
            "purge_default_rules": false,
            "purge_rules": true,
            "resource_group": "DIDA-IDSA18-DV1617-H21-LP2",
            "rules": [
                {
                    "access": "Allow",
                    "description": null,
                    "destination_address_prefix": "*",
                    "destination_application_security_groups": null,
                    "destination_port_range": 22,
                    "direction": "Inbound",
                    "name": "SSH",
                    "priority": 1001,
                    "protocol": "Tcp",
                    "source_address_prefix": "0.0.0.0/0",
                    "source_application_security_groups": null,
                    "source_port_range": "*"
                },
                {
                    "access": "Allow",
                    "description": null,
                    "destination_address_prefix": "*",
                    "destination_application_security_groups": null,
                    "destination_port_range": 3306,
                    "direction": "Inbound",
                    "name": "MYSQL",
                    "priority": 1002,
                    "protocol": "Tcp",
                    "source_address_prefix": "0.0.0.0/0",
                    "source_application_security_groups": null,
                    "source_port_range": "*"
                }
            ],
            "secret": null,
            "state": "present",
            "subscription_id": null,
            "tags": {
                "StudentId": "idsa18"
            },
            "tenant": null
        }
    },
    "msg": "Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on DESKTOP-BADTR07's Python /usr/bin/python3. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"
}

点子列表给我

adal                                  1.2.7
alembic                               1.7.5
ansible                               4.8.0
ansible-core                          2.11.7
applicationinsights                   0.11.10
argcomplete                           1.12.3
azure                                 4.0.0
azure-applicationinsights             0.1.0
azure-batch                           4.1.3
azure-cli-core                        2.26.1
azure-cli-telemetry                   1.0.6
azure-common                          1.1.11
azure-core                            1.21.1
azure-cosmosdb-nspkg                  2.0.2
azure-cosmosdb-table                  1.0.6
azure-datalake-store                  0.0.52
azure-eventgrid                       1.3.0
azure-graphrbac                       0.61.1
azure-identity                        1.7.0
azure-keyvault                        1.0.0a1
azure-keyvault-secrets                4.3.0
azure-loganalytics                    0.1.1
azure-mgmt                            4.0.0
azure-mgmt-advisor                    1.0.1
azure-mgmt-apimanagement              0.2.0
azure-mgmt-applicationinsights        0.1.1
azure-mgmt-authorization              0.51.1
azure-mgmt-automation                 0.1.1
azure-mgmt-batch                      5.0.1
azure-mgmt-batchai                    2.0.0
azure-mgmt-billing                    0.2.0
azure-mgmt-cdn                        3.0.0
azure-mgmt-cognitiveservices          3.0.0
azure-mgmt-commerce                   1.0.1
azure-mgmt-compute                    10.0.0
azure-mgmt-consumption                2.0.0
azure-mgmt-containerinstance          1.4.0
azure-mgmt-containerregistry          2.0.0
azure-mgmt-containerservice           9.1.0
azure-mgmt-core                       1.2.2
azure-mgmt-cosmosdb                   0.5.2
azure-mgmt-datafactory                0.6.0
azure-mgmt-datalake-analytics         0.6.0
azure-mgmt-datalake-nspkg             2.0.0
azure-mgmt-datalake-store             0.5.0
azure-mgmt-datamigration              1.0.0
azure-mgmt-devspaces                  0.1.0
azure-mgmt-devtestlabs                3.0.0
azure-mgmt-dns                        2.1.0
azure-mgmt-eventgrid                  1.0.0
azure-mgmt-eventhub                   2.0.0
azure-mgmt-hanaonazure                0.1.1
azure-mgmt-hdinsight                  0.1.0
azure-mgmt-iotcentral                 0.1.0
azure-mgmt-iothub                     0.7.0
azure-mgmt-iothubprovisioningservices 0.2.0
azure-mgmt-keyvault                   1.1.0
azure-mgmt-loganalytics               1.0.0
azure-mgmt-logic                      3.0.0
azure-mgmt-machinelearningcompute     0.4.1
azure-mgmt-managedservices            1.0.0
azure-mgmt-managementgroups           0.2.0
azure-mgmt-managementpartner          0.1.1
azure-mgmt-maps                       0.1.0
azure-mgmt-marketplaceordering        0.1.0
azure-mgmt-media                      1.0.1
azure-mgmt-monitor                    3.0.0
azure-mgmt-msi                        0.2.0
azure-mgmt-network                    12.0.0
azure-mgmt-notificationhubs           2.0.0
azure-mgmt-nspkg                      2.0.0
azure-mgmt-policyinsights             0.1.0
azure-mgmt-powerbiembedded            2.0.0
azure-mgmt-privatedns                 0.1.0
azure-mgmt-rdbms                      1.9.0
azure-mgmt-recoveryservices           0.4.0
azure-mgmt-recoveryservicesbackup     0.6.0
azure-mgmt-redis                      5.0.0
azure-mgmt-relay                      0.1.0
azure-mgmt-reservations               0.2.1
azure-mgmt-resource                   10.2.0
azure-mgmt-scheduler                  2.0.0
azure-mgmt-search                     3.0.0
azure-mgmt-servicebus                 0.5.3
azure-mgmt-servicefabric              0.2.0
azure-mgmt-signalr                    0.1.1
azure-mgmt-sql                        0.10.0
azure-mgmt-storage                    11.1.0
azure-mgmt-subscription               0.2.0
azure-mgmt-trafficmanager             0.50.0
azure-mgmt-web                        0.41.0
azure-nspkg                           2.0.0
azure-servicebus                      0.21.1
azure-servicefabric                   6.3.0.0
azure-servicemanagement-legacy        0.20.7
azure-storage                         0.35.1
azure-storage-blob                    1.5.0
azure-storage-common                  1.4.2
azure-storage-file                    1.4.0
azure-storage-queue                   1.4.0
bcrypt                                3.2.0
boto                                  2.49.0
boto3                                 1.20.26
botocore                              1.23.26
certifi                               2021.10.8
cffi                                  1.15.0
chardet                               4.0.0
click                                 8.0.3
colorama                              0.4.4
cryptography                          3.3.2
dnspython                             2.1.0
dominate                              2.6.0
email-validator                       1.1.3
Flask                                 2.0.2
Flask-Bootstrap                       3.3.7.1
Flask-Login                           0.5.0
Flask-Migrate                         3.1.0
Flask-Moment                          1.0.2
Flask-SQLAlchemy                      2.5.1
Flask-WTF                             0.15.1
greenlet                              1.1.2
gunicorn                              20.1.0
humanfriendly                         9.2
idna                                  2.10
isodate                               0.6.1
itsdangerous                          2.0.1
Jinja2                                3.0.3
jmespath                              0.10.0
knack                                 0.8.2
Mako                                  1.1.6
MarkupSafe                            2.0.1
msal                                  1.16.0
msal-extensions                       0.3.1
msrest                                0.6.21
msrestazure                           0.6.4
oauthlib                              3.1.1
packaging                             21.3
paramiko                              2.9.1
pip                                   21.3.1
pkg_resources                         0.0.0
pkginfo                               1.8.2
portalocker                           1.7.1
psutil                                5.9.0
pycparser                             2.21
Pygments                              2.11.1
PyJWT                                 2.3.0
PyMySQL                               1.0.2
PyNaCl                                1.4.0
pyOpenSSL                             21.0.0
pyparsing                             3.0.6
python-dateutil                       2.8.2
python-dotenv                         0.19.1
PyYAML                                6.0
requests                              2.25.1
requests-oauthlib                     1.3.0
resolvelib                            0.5.4
s3transfer                            0.5.0
setuptools                            59.6.0
six                                   1.16.0
SQLAlchemy                            1.4.28
tabulate                              0.8.9
urllib3                               1.26.7
visitor                               0.1.3
Werkzeug                              2.0.2
WTForms                               3.0.0
xmltodict                             0.12.0

【问题讨论】:

标签: python ansible devops


【解决方案1】:

module_stderr 告诉您 Ansible 找不到 Python 解释器。您需要将其设置在某处,例如在您的库存中。根据您的情况,您可能必须更改实际路径。应该看起来像这样。

[groupname]
ansible_python_interpreter=/usr/bin/python3

您也可以通过设置变量在剧本本身内进行设置。

- hosts: localhost

  vars:
    ansible_python_interpreter: /usr/bin/python3

  tasks:
    .....

【讨论】:

  • 谢谢这让我更进一步,但现在我面临一个新问题ModuleNotFoundError: No module named 'azure.mgmt.privatedns'。我已经检查过包裹是否存在
  • 您安装了哪些软件包?你一定错过了一个或多个。
  • 我已经用我已安装的软件包列表更新了这个问题。请拍下,提前谢谢:)
  • 您使用的是哪个 python 解释器以及您使用哪个版本的 pip 来安装软件包。它们必须相同。
猜你喜欢
  • 2018-02-07
  • 1970-01-01
  • 2020-12-04
  • 2019-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多