ansible - Ansiblle 因保管库而失败
问题描述
我创建了一个包含以下内容的加密 credent.yml 文件:
sudo_password: whatever
我可以用 解密ansible-vault view credent.yml
,但是我不能在这个剧本中使用它:
---
- name: "Ansible test localhost"
hosts: 127.0.0.1
connection: local
tasks:
- name: check file existance
ansible.builtin.stat: path=/tmp/err
register: result
- name: Print error if file does not exist
ansible.builtin.fail:
msg: "The file or directory does not exists"
when: not result.stat.exists
- name: Print debug message if it exists
ansible.builtin.debug:
msg: "The file or directory exists"
when: result.stat.exists
become: yes
vars:
ansible_become_password: '{{ sudo_password }}'
这是输出:
ansible-playbook --ask-vault-pass --extra-vars '@credent.yml' checkfile.yml
Vault password:
ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: No JSON object could be decoded
Syntax Error while loading YAML.
did not find expected node content
The error appears to be in '/root/test-ansible/credent.yml': line 1, column 16, but may
be elsewhere in the file depending on the exact syntax problem.
Ansible 版本:
ansible 2.9.18
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.13 (default, Aug 22 2020, 10:03:02) [GCC 6.3.0 20170516]
注意:如果我ansible_python_interpreter: /usr/bin/python3
在剧本中设置它会失败
我做错了什么?
解决方案
我检查了 credent.yml 并运行
yamllint credent.yml
这向我展示了语法错误。
我已---
在文件顶部添加并转义了特殊字符。
这样做剧本运行良好。
推荐阅读
- excel - 运行时错误“1004”:应用程序定义或对象定义错误
- python - TensorFlow 2.0:无法运行最小 TF 教程:TypeError:无法将 int64 转换为张量或操作
- qliksense - 为什么 MoneyFormat 脚本变量不起作用?
- android - Android - Camera X - 如何检查设备是否有前置摄像头 CameraX.LensFacing.FRONT
- shiny - 如何在 R 闪亮的应用程序中操作数据框
- vue.js - 在Vue中将数据从子元素返回到父元素
- javascript - 如何使用提交输入按钮作为当前选项卡中另一个网页的链接?
- firebase - 要链接到电子邮件的 Firebase 匿名用户
- reactjs - 如何确保在 react-redux 中调用 componentDidMount() 之前返回更新的状态?
- php - 如何请求获取价值?