使用ansible的adoc命令行在受控端主机tmp下创建一个ansiblefile文件夹并在这个文件夹下面创建testtxt文件设定文件主、组、权限
您可以使用以下Ansible的ad-hoc命令来在受控主机上创建一个ansiblefile文件夹,并在其中创建test.txt文件,并设置文件的所有者、组和权限。
ansible <inventory_group> -m file -a "path=/tmp/ansiblefile state=directory"
ansible <inventory_group> -m file -a "path=/tmp/ansiblefile/test.txt state=touch"
ansible <inventory_group> -m file -a "path=/tmp/ansiblefile/test.txt owner=<user> group=<group> mode=<permission>"
请将<inventory_group>替换为你的Ansible inventory中包含要操作的受控主机的组名。将<user>替换为所需的文件所有者用户名,<group>替换为所需的文件组名,<permission>替换为所需的文件权限。
例如,要在名为web_servers的组中的所有受控主机上创建目录和文件,并将其设置为root用户的所有者,root组和权限为644,可以执行以下命令:
ansible web_servers -m file -a "path=/tmp/ansiblefile state=directory"
ansible web_servers -m file -a "path=/tmp/ansiblefile/test.txt state=touch"
ansible web_servers -m file -a "path=/tmp/ansiblefile/test.txt owner=root group=root mode=644"
请根据您的需求修改命令中的参数。
原文地址: https://www.cveoy.top/t/topic/i5YP 著作权归作者所有。请勿转载和采集!