Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
496 views
in Technique[技术] by (71.8m points)

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

在写一个自动化部署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)]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...