bash 如何使用 Ansible chmod +xa 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40505772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:27:12  来源:igfitidea点击:

How to chmod +x a file with Ansible?

bashansibleansible-playbook

提问by Atlantic0

What is the best way to chmod + x a file with ansible.

使用ansible chmod + xa 文件的最佳方法是什么?

Converting the following script to ansible format.

将以下脚本转换为 ansible 格式。

mv /tmp/metadata.sh /usr/local/bin/meta.sh
chmod +x /usr/local/bin/meta.sh

This is what I have so far..

这是我到目前为止..

- name: move /tmp/metadata.sh to /usr/local/bin/metadata.sh
  command: mv /tmp/metadata.sh /usr/local/bin/metadata.sh

回答by heemayl

ansiblehas modeparameter in filemodule exactly for this purpose.

ansible为此modefile模块中有参数。

To add execute permission for everyone (i.e. chmod a+xon command line):

为所有人添加执行权限(即chmod a+x在命令行上):

- name: Changing perm of "/foo/bar.sh", adding "+x"
  file: dest=/foo/bar.sh mode=a+x

Symbolic modes are supported since version 1.8, on a prior version you need to use the octal bits.

从 1.8 版开始支持符号模式,在之前的版本中您需要使用八进制位。

回答by Adam

The modeparameter should be specified when using the copymodule.

mode使用复制模块时需要指定该参数。

Example:

例子:

- name: copy file and set permissions
  copy:
    src: script.sh
    dest: /directory/script.sh
    mode: a+x