【发布时间】:2021-03-11 08:18:49
【问题描述】:
我正在尝试运行 ansible-playbook 并得到以下异常:
TASK [deploy aws auth configmap] ***********************************************
task path: /Kubernetes-in-Production-Best-Practices/Chapter04/ansible/tasks/aws-auth.yaml:1
The full traceback is:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/ansible/executor/task_executor.py", line 116, in run
items = self._get_loop_items()
File "/usr/local/lib/python3.9/site-packages/ansible/executor/task_executor.py", line 250, in _get_loop_items
items = templar.template(self._task.loop)
File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 822, in template
return [self.template(
File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 822, in <listcomp>
return [self.template(
File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 789, in template
result = self.do_template(
File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 1057, in do_template
res = j2_concat(rf)
File "<template>", line 15, in root
File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 257, in wrapper
return list(ret)
File "/usr/local/lib/python3.9/site-packages/yaml/__init__.py", line 127, in load_all
loader = Loader(stream)
File "/usr/local/lib/python3.9/site-packages/yaml/loader.py", line 34, in __init__
Reader.__init__(self, stream)
File "/usr/local/lib/python3.9/site-packages/yaml/reader.py", line 74, in __init__
self.check_printable(stream)
File "/usr/local/lib/python3.9/site-packages/yaml/reader.py", line 143, in check_printable
raise ReaderError(self.name, position, ord(character),
yaml.reader.ReaderError: unacceptable character #x001b: special characters are not allowed
in "<unicode string>", position 281
fatal: [localhost]: FAILED! => {
"msg": "Unexpected failure during module execution.",
"stdout": ""
}
这是返回异常的命令:
ansible-playbook -i \
../../inventories/packtclusters/ \
-e "worker_iam_role_arn=$(terraform output worker_iam_role_arn) \
cluster_name=$(terraform output cluster_full_name) \
aws_default_region=$(terraform output aws_region)" \
../../cluster.yaml
这是发生异常的“aws-auth.yaml”文件:
- name: deploy aws auth configmap
k8s:
definition: "{{ item }}"
kubeconfig: "{{ k8s_kubeconfig }}"
state: "{{ k8s_manifests_state }}"
force: "{{ k8s_force }}"
loop:
- "{{ lookup('template', k8s_manifests_base_dir + 'auth/aws-auth.yaml') | from_yaml_all | list }}"
register: k8s_result
until: k8s_result is success
retries: 3
delay: 2
no_log: "{{ k8s_no_log }}"
这是我安装 ansible 的步骤:
virtualenv $HOME/Envs/ansible-k8s-workspace
source $HOME/Envs/ansible-k8s-workspace/bin/activate
pip install 'ansible<3.0' openshift pyyaml requests 'kubernetes<12.0'
这里是技术信息:
Operating System: MacOS X
Python 3.9.2
pip 21.0.1 from /Envs/ansible-k8s-workspace/lib/python3.9/site-packages/pip (python 3.9)
ansible 2.10.6
config file = None
configured module search path = ['/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.9.2 (default, Feb 24 2021, 13:26:09) [Clang 12.0.0 (clang-1200.0.32.29)]
另外,这里是命令的完整调试输出:
ansible-playbook -i \
../../inventories/packtclusters/ \
-e "worker_iam_role_arn=$(terraform output worker_iam_role_arn) \
cluster_name=$(terraform output cluster_full_name) \
aws_default_region=$(terraform output aws_region)" \
../../cluster.yaml -vvv
ansible-playbook 2.10.6
config file = None
configured module search path = ['/Users/skliarm/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
executable location = /usr/local/bin/ansible-playbook
python version = 3.9.2 (default, Feb 24 2021, 13:26:09) [Clang 12.0.0 (clang-1200.0.32.29)]
No config file found; using defaults
host_list declined parsing /Users/skliarm/git/kubernetes/Kubernetes-in-Production-Best-Practices/Chapter04/ansible/inventories/packtclusters/hosts as it did not pass its verify_file() method
script declined parsing /Users/skliarm/git/kubernetes/Kubernetes-in-Production-Best-Practices/Chapter04/ansible/inventories/packtclusters/hosts as it did not pass its verify_file() method
auto declined parsing /Users/skliarm/git/kubernetes/Kubernetes-in-Production-Best-Practices/Chapter04/ansible/inventories/packtclusters/hosts as it did not pass its verify_file() method
Parsed /Users/skliarm/git/kubernetes/Kubernetes-in-Production-Best-Practices/Chapter04/ansible/inventories/packtclusters/hosts inventory source with ini plugin
statically imported: /Users/skliarm/git/kubernetes/Kubernetes-in-Production-Best-Practices/Chapter04/ansible/tasks/aws-auth.yaml
redirecting (type: modules) ansible.builtin.k8s to community.kubernetes.k8s
statically imported: /Users/skliarm/git/kubernetes/Kubernetes-in-Production-Best-Practices/Chapter04/ansible/tasks/namespaces.yaml
redirecting (type: modules) ansible.builtin.k8s to community.kubernetes.k8s
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: cluster.yaml *********************************************************
1 plays in ../../cluster.yaml
PLAY [deploy k8s add-ons] ******************************************************
META: ran handlers
TASK [deploy aws auth configmap] ***********************************************
task path: /Users/skliarm/git/kubernetes/Kubernetes-in-Production-Best-Practices/Chapter04/ansible/tasks/aws-auth.yaml:1
The full traceback is:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/ansible/executor/task_executor.py", line 116, in run
items = self._get_loop_items()
File "/usr/local/lib/python3.9/site-packages/ansible/executor/task_executor.py", line 250, in _get_loop_items
items = templar.template(self._task.loop)
File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 822, in template
return [self.template(
File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 822, in <listcomp>
return [self.template(
File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 789, in template
result = self.do_template(
File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 1057, in do_template
res = j2_concat(rf)
File "<template>", line 15, in root
File "/usr/local/lib/python3.9/site-packages/ansible/template/__init__.py", line 257, in wrapper
return list(ret)
File "/usr/local/lib/python3.9/site-packages/yaml/__init__.py", line 127, in load_all
loader = Loader(stream)
File "/usr/local/lib/python3.9/site-packages/yaml/loader.py", line 34, in __init__
Reader.__init__(self, stream)
File "/usr/local/lib/python3.9/site-packages/yaml/reader.py", line 74, in __init__
self.check_printable(stream)
File "/usr/local/lib/python3.9/site-packages/yaml/reader.py", line 143, in check_printable
raise ReaderError(self.name, position, ord(character),
yaml.reader.ReaderError: unacceptable character #x001b: special characters are not allowed
in "<unicode string>", position 281
fatal: [localhost]: FAILED! => {
"msg": "Unexpected failure during module execution.",
"stdout": ""
}
PLAY RECAP *********************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
完整的源代码可以在这里找到:https://github.com/PacktPublishing/Kubernetes-in-Production-Best-Practices/tree/master/Chapter04
【问题讨论】:
-
能否提供 ansible playbook 运行的调试输出?
-
#001B是转义字符,这是一个隐藏字符,所以,很可能你已经将它复制粘贴到你的代码中,可能在 auth/aws-auth.yaml i> 正如错误消息所指出的那样。 -
@Mr.J 我提供了完整的调试输出,谢谢
-
@β.εηοιτ.βε 我不认为这个文件包含转义字符。似乎 ansible 以某种方式添加了它,尽管我不确定。这是文件的链接:github.com/PacktPublishing/…
-
@β.εηοιτ.βε 根据调试输出,这个转义字符必须在第 1 行第 1 列,但我怀疑它是否存在,虽然我无法证明。也许有一个在线编辑器,可以显示隐形字符?
标签: python pip ansible virtualenv