如何使用Ansible自动化数据模式



*****************************************************************************************************************************************************

我想用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 == "rnStatus code = 0 rn"

脚本:

#!/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"

最新更新