ansible诡异报错,提示引号缺失?

发布于 2022-09-12 04:42:21 字数 2479 浏览 24 评论 0

在写一个自动化部署mysql5.7.26的role时,莫名其妙出现以下错误,多次google后尝试无果,所以来请求一下大牛解答.

[root@ansible ansible]# ansible-playbook role-mysql.yml 
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 key

The error appears to be in '/root/ansible/roles/mysql/tasks/initialized.yml': line 2, column 23, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: Initialized
  shell: {{ app_dir }}/mysql-5.7.26/bin/mysqld --initialize-insecure --basedir={{ app_dir }}/mysql-5.7.26 --datadir={{ data_dir }} --user={{ user }}
                      ^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:

    with_items:
      - {{ foo }}

Should be written as:

    with_items:
      - "{{ foo }}"

起先该role此处使用的是绝对路径,多次测试通过,于是将路径改为用变量替代之后才开始出现此报错.

目录结构:

[root@ansible ansible]# tree roles/mysql/
roles/mysql/
├── files
│   └── mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
├── tasks
│   ├── auto_poweron.yml
│   ├── config_file.yml
│   ├── configurate_service_and_start.yml
│   ├── copy_file_and_configurate.yml
│   ├── create_dir.yml
│   ├── env_var.yml
│   ├── initialized.yml
│   ├── main.yml
│   ├── password.yml
│   ├── permission.yml
│   └── user_and_group.yml
├── templates
│   └── my.cnf.j2
└── vars
    └── main.yml

4 directories, 14 files

变量文件:

[root@ansible ansible]# cat roles/mysql/vars/main.yml 
app_dir: /app
data_dir: /data/mysql/data
log_dir: /data/mysql/logs
user: mysql
password: 123.com

系统版本:

[root@ansible ansible]# uname -a;cat /etc/redhat-release
Linux ansible 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
CentOS Linux release 7.6.1810 (Core) 

ansible版本:

[root@ansible ansible]# ansible --version
ansible 2.9.10
  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/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文