在运行本地脚本之前更改目录

时间:2016-12-19 17:28:51

标签: shell ansible

我想在远程节点上运行本地脚本之前更改目录。脚本不允许chdir作为参数。怎么做?

---
- hosts: centos
  remote_user: kk
  sudo: true
  tasks:
   - name: Run local script on  remote node
     script: /home/Ansible/VM/monitor/space.sh > space_result.txt
     args:
      chdir: /home/Ansible   # something like that
      creates: space_result.txt

1 个答案:

答案 0 :(得分:1)

your comment(" Playbook成功,文件被复制但没有输出文件。"):

重定向在- name: Ensure local script is copied to the remote node copy: src: ~/Ansible/VM/monitor/space.sh dest: /home/kk/space.sh owner: kk mode: 0744 - name: Run copied script on the remote node shell: /home/kk/space.sh > space_result.txt args: chdir: /home/kk/Ansible creates: space_result.txt 模块中不起作用。您应该使用shell代替:

import java.util.Scanner;

public class BarChart {

    private int NumberOfValues;  
    private String [] valueName; 
    private int [] value; 
    private int currentMax; 
    public int counter; 
    public int i; 
    Scanner input = new Scanner(System.in);

    public BarChart(String string) {

    }
    public void setValues()
        {
            System.out.println("How many sets of numbers would you like to enter?"); 
            NumberOfValues = input.nextInt();
            value = new int  [NumberOfValues];
            valueName = new String [NumberOfValues]; 

            for (int i =0; i <value.length; i++);
            {
                System.out.printf("Please enter the name of the set", + i);
                valueName [i] = input.nextLine(); 
                System.out.printf("Please enter the value ", + i);
                value[i] = input.nextInt(); 
            }

        }