ansible管理openstack Cloud mycloud was not found问题解决

  • 在学习ansible,openstack.cloud 模块中遇到 Cloud mycloud was not found的问题。
The full traceback is:
WARNING: The below traceback may *not* be related to the actual failure.
  File "/tmp/ansible_openstack.cloud.identity_domain_payload_fb363T/ansible_openstack.cloud.identity_domain_payload.zip/ansible_collections/openstack/cloud/plugins/module_utils/openstack.py", line 372, in openstack_cloud_from_module
    return sdk, sdk.connect(**cloud_config)
  File "/usr/lib/python2.7/site-packages/openstack/__init__.py", line 59, in connect
    options=options, **kwargs)
  File "/usr/lib/python2.7/site-packages/openstack/config/__init__.py", line 36, in get_cloud_region
    return config.get_one(options=parsed_options, **kwargs)
  File "/usr/lib/python2.7/site-packages/openstack/config/loader.py", line 1075, in get_one
    config = self._get_base_cloud_config(cloud, profile)
  File "/usr/lib/python2.7/site-packages/openstack/config/loader.py", line 483, in _get_base_cloud_config
    name=name))
fatal: [192.168.116.200]: FAILED! => {
    "changed": false, 
    "invocation": {
        "module_args": {
            "api_timeout": null, 
            "auth": null, 
            "auth_type": null, 
            "availability_zone": null, 
            "ca_cert": null, 
            "client_cert": null, 
            "client_key": null, 
            "description": "An Example Domain", 
            "enabled": true, 
            "interface": "public", 
            "name": "example", 
            "region_name": null, 
            "state": "present", 
            "timeout": 180, 
            "validate_certs": null, 
            "wait": true
        }
    }, 
    "msg": "Cloud mycloud was not found."
}
...ignoring
  1. 我们先看下我们编写的文件,从理论上来讲这样写是没问题的,但是一直执行失败
- hosts: controller
  user: root
  tasks:
    - openstack.cloud.auth:
        cloud: mycloud
    - openstack.cloud.identity_domain:
        cloud: mycloud
        state: present
        name: example
        description: An Example Domain
      ignore_errors: yes
    - name: Show service catalog
      debug:
        var: service_catalog

clouds:
  mycloud:
    auth:
      auth_url: http://192.168.116.200:5000/v3
      username: admin
      password: '000000'
      project_name: admin
      project_domain_name: "Default"
      user_domain_name: "Default"
  1. 这边小小看一下源码
 cat  /root/.ansible/collections/ansible_collections/openstack/cloud/plugins/inventory/openstack.py

clouds_yaml_path:
        description: |
            Override path to clouds.yaml file. If this value is given it
            will be searched first. The default path for the
            ansible inventory adds /etc/ansible/openstack.yaml and
            /etc/ansible/openstack.yml to the regular locations documented
            at https://docs.openstack.org/os-client-config/latest/user/configuration.html#config-files
        type: list
        elements: str
        env:
            - name: OS_CLIENT_CONFIG_FILE 
  1. 可以看出寻找该文件是基于OS_CLIENT_CONFIG_FILE 参数

- hosts: controller
  user: root
  tasks:
    - openstack.cloud.auth:
        cloud: mycloud
    - openstack.cloud.identity_domain:
        cloud: mycloud
        state: present
        name: example
        description: An Example Domain
      ignore_errors: yes
    - name: Show service catalog
      debug:
        var: service_catalog
    - name: Show service catalog
      shell: echo $OS_CLIENT_CONFIG_FILE >> /root/test.txt

  1. 这里调试下playbook 并执行发现在 /root/test.txt中,文件值为空,后来参考一下博主的博文,学习到了login shell 和 non-login shell的区别

https://blog.csdn.net/u010871982/article/details/78525367

  1. 解决方案就是在被控端,当然也可以直接在playbook里面用shell写入,/etc/bashrc中写入export OS_CLIENT_CONFIG_FILE=指定文件的名称路径
vi /etc/bashrc
export OS_CLIENT_CONFIG_FILE=/etc/openstack/clouds.yaml
  • 已解决
[root@controller roles]# ansible-playbook /etc/ansible/roles/test.yml -v
Using /etc/ansible/ansible.cfg as config file

PLAY [controller] *********************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************
ok: [192.168.116.200]

TASK [openstack.cloud.auth] ***********************************************************************************************************************
ok: [192.168.116.200] => {"ansible_facts": {"auth_token": "gAAAAABiZKYPedp1LRZz07FfmCPrn5QxeY3GQAQD91iKWu7Wq00D2bomPMYPRi7OtZ2fXKhHY8SJ1reMJ-0WETMeNDLFi3c1eNB41iSdfwgipixl2cZJKZJseAEL-pTwvVtAdCtU1cf_TDE7JVa13q6DrYhgVZMT-zLH9C_Z1rixOhDtIhA9H4g", "service_catalog": [{"endpoints": [{"id": "13e8b466eee944c6866d2267d4b4bf20", "interface": "admin", "region": "RegionOne", "region_id": "RegionOne", "url": "http://controller:5000/v3/"}, {"id": "d92249c8068d48cc81ff52c9694ca9ff", "interface": "public", "region": "RegionOne", "region_id": "RegionOne", "url": "http://controller:5000/v3/"}, {"id": "fece7da268da4f6689f97608f1018725", "interface": "internal", "region": "RegionOne", "region_id": "RegionOne", "url": "http://controller:5000/v3/"}], "id": "811f4463f8d94fe4aa72cadb92ec0d1d", "name": "keystone", "type": "identity"}]}, "changed": false}

TASK [openstack.cloud.identity_domain] ************************************************************************************************************
ok: [192.168.116.200] => {"changed": false, "domain": {"description": "An Example Domain", "id": "2740142dd6664fa2828ed9e1233fd912", "is_enabled": true, "links": {"self": "http://controller:5000/v3/domains/2740142dd6664fa2828ed9e1233fd912"}, "name": "example"}, "id": "2740142dd6664fa2828ed9e1233fd912"}

TASK [Show service catalog] ***********************************************************************************************************************
ok: [192.168.116.200] => {
    "service_catalog": [
        {
            "endpoints": [
                {
                    "id": "13e8b466eee944c6866d2267d4b4bf20", 
                    "interface": "admin", 
                    "region": "RegionOne", 
                    "region_id": "RegionOne", 
                    "url": "http://controller:5000/v3/"
                }, 
                {
                    "id": "d92249c8068d48cc81ff52c9694ca9ff", 
                    "interface": "public", 
                    "region": "RegionOne", 
                    "region_id": "RegionOne", 
                    "url": "http://controller:5000/v3/"
                }, 
                {
                    "id": "fece7da268da4f6689f97608f1018725", 
                    "interface": "internal", 
                    "region": "RegionOne", 
                    "region_id": "RegionOne", 
                    "url": "http://controller:5000/v3/"
                }
            ], 
            "id": "811f4463f8d94fe4aa72cadb92ec0d1d", 
            "name": "keystone", 
            "type": "identity"
        }
    ]
}

TASK [Show service catalog] ***********************************************************************************************************************
changed: [192.168.116.200] => {"changed": true, "cmd": "echo $OS_CLIENT_CONFIG_FILE >> /root/test.txt", "delta": "0:00:00.001907", "end": "2022-04-23 21:21:20.798917", "rc": 0, "start": "2022-04-23 21:21:20.797010", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

PLAY RECAP ****************************************************************************************************************************************
192.168.116.200            : ok=5    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[root@controller roles]# 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

啊酒弟弟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值