- 在学习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
- 我们先看下我们编写的文件,从理论上来讲这样写是没问题的,但是一直执行失败
- 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"
- 这边小小看一下源码
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
- 可以看出寻找该文件是基于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
- 这里调试下playbook 并执行发现在 /root/test.txt中,文件值为空,后来参考一下博主的博文,学习到了login shell 和 non-login shell的区别
https://blog.csdn.net/u010871982/article/details/78525367
- 解决方案就是在被控端,当然也可以直接在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]#