【问题标题】:Running a remote script with parameters using ansible script module使用 ansible 脚本模块运行带有参数的远程脚本
【发布时间】:2017-11-08 17:12:23
【问题描述】:

我正在尝试在远程主机上执行一个带有单个参数(文件路径+名称)的脚本。

- name: Run Script
  hosts: host_alias
  tasks:
     - script: "{{ script_file_path }}/script.sh"
       with_items: 
         - "{{ target_file_path }}/{{ target_file_name }}.conf"

目前,我遇到了语法错误。这是执行此操作的最佳方法吗?如果是,正确的语法是什么?

【问题讨论】:

    标签: bash syntax ansible


    【解决方案1】:

    这里没有语法错误的原因(实际上,如果只指定变量,则没有任何错误的原因)。


    您定义了一个循环,但没有使用迭代数据。 至少,您需要添加对item 的引用:

    - name: Run Script
      hosts: host_alias
      tasks:
        - script: "{{ script_file_path }}/script.sh {{ item }}"
          with_items: 
            - "{{ target_file_path }}/{{ target_file_name }}.conf"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-30
      • 1970-01-01
      • 2014-07-04
      • 2019-07-26
      • 2020-01-24
      • 2012-08-21
      • 1970-01-01
      相关资源
      最近更新 更多