ansible - 如何使用 Ansible 自动化 DataStage 作业?
问题描述
*****************************[更新]****************** ************************
我想用 Ansible 编辑一个脚本。✔ 已解决
我找到了替换模块,但在尝试运行剧本时出现错误。✔ 已解决
我希望每个传递给变量“结果”的值做一些不同的事情。✘ 未解决
- name: Automation of a job in DataStage
hosts: dshost
vars_prompt:
- name: project
prompt: 'Enter the project'
private: no
- name: j0b
prompt: 'Enter the job'
private: no
tasks:
- name: Copying file script to modify then
copy:
src: /home/ansible/Downloads/script.sh
dest: /home/dsadm/script.sh
- name: Replaces the variables that we've passed
replace:
path: /home/dsadm/script.sh
regexp: '{{ item.regexp1 }}'
replace: '{{ item.replace }}'
backup: yes
with_items:
- { regexp1: 'project', replace: '{{ project }}' }
- { regexp1: 'j0b', replace: '{{ j0b }}' }
- name: Running the script
command: sh /home/dsadm/script.sh
register: result
- name: Check if the script is executed correctly
debug:
msg: "The file script was executed without errors"
when: result.stdout == "\r\nStatus code = 0 \r\n"
剧本 :
#!/bin/bash
cd /opt/IBM/InformationServer/Server/DSEngine/
. ./dsenv
$DSHOME/bin/dsjob -run project j0b
rtn=$?
**************(更新)********* 输出为:
sudo ansible-playbook testJob.yml
[sudo] password for ansible:
Enter the project: dstage1
Enter the job: limits
PLAY [Automation of a job in DataStage] ****************************************************
TASK [Gathering Facts] *********************************************************************
ok: [172.16.2.112]
TASK [Copying file script to modify then] **************************************************
changed: [172.16.2.112]
TASK [Replaces the variables that we've passed] ********************************************
changed: [172.16.2.112] => (item={u'regexp1': u'project', u'replace': u'dstage1'})
changed: [172.16.2.112] => (item={u'regexp1': u'j0b', u'replace': u'limits'})
TASK [Running the script] ******************************************************************
changed: [172.16.2.112]
TASK [Check if the script is executed correctly] *******************************************
skipping: [172.16.2.112]
PLAY RECAP *********************************************************************************
172.16.2.112 : ok=4 changed=3 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
更新 04/07/2019
- 我怎样才能根据可变结果使我的剧本做我想做的事?
解决方案
正确的语法是
- name: Step one
hosts: xxx.xx.x.xxx
vars_prompt:
...
这是错误的原因
"ERROR! the field 'hosts' is required but was not set"
推荐阅读
- sql - postgres 中的数据库链接正在查看另一个本地主机图像:关系表名不存在
- ruby-on-rails - Azure DevOps - 自动运行 rails 迁移
- c++ - 如何使用带有函数作为参数的可变参数函数并将它们传递给指针
- css - 在 Rails 中高效加载 CSS 和 JS(“为所有静态资产使用 CDN”)
- powershell - 使用公司代理远程调用 Invoke-WebRequest 的问题
- python - 浮点除以零 Python
- c# - 如何在 Windows 10 中使用 C# 将程序固定到任务栏
- kubernetes - 在 kubernetes 中创建持久卷声明时未应用 Null 终结器
- docker - 是否可以将一个 docker 容器中的网络共享挂载传播给同一主机上的其他容器?
- soap - 是否可以通过 Google 跟踪代码管理器中的自定义 HTML 标记发送 SOAP API 调用