我有一个shell脚本,其输出是以下格式的回声
<variable_1>;<variable_2>;<variable_3>等
我想使用这些变量并运行一个mysql查询来更新这样的数据库
mysql -u<user> -p<password> -h<host> -e'insert into test_table values ("variable_1","variable_2","variable_3")'
我的ansible剧本看起来像这样.
---
- hosts: infoServers
sudo: yes
gather_facts: no
tasks:
- name: gather info
script: get_hostdata.sh
register: result
- name: print result
local_action: command mysql -uuser -ppassword -h192.168.101.10 ansible_db -e'insert into test_table values ("{{ item[0] }}","{{ item[1] }}","{{ item[3] }});'
with_items: [ result.stdout.split(';')[0], result.stdout.split(';')[1], result.stdout.split(';')[2] ]
Run Code Online (Sandbox Code Playgroud)
错误:加载YAML脚本时的语法错误,test_variables.yml
基本上我希望能够使用shell命令的输出,将其拆分为一些变量,并能够在进一步的ansible动作中使用它们.能否指导我如何正确访问变量?
谢谢