我想在Linux/Debian上用ansible创建一个命名管道。在shell脚本中,我将使用命令mkfifo创建管道。现在我想知道是否有内置模块方法,但我在ansible的内置模块中找不到任何东西。在谷歌上搜索这个问题也不会产生任何有意义的结果。
我的方法只是使用ansible执行一个shell命令,然后像这样执行mkfifo:
- name: Create named pipe
shell: "mkfifo testpipe"然而,准确地说,我需要检查管道是否已经存在,如果是,我需要检查文件类型等等。
我打赌有一个方便的方法,但我就是找不到。
非常感谢你的帮助
编辑:我现在就是这样做的。我打赌有些案子我还没处理好。
- name: Check for existing pipe
shell: "test -p {{ pipe_file }}"
register: pipe_file_test
become: true
changed_when: false
- name: Delete pipe_file if its not a pipe
file:
name: "{{ pipe_file }}"
state: absent
when: pipe_file_test.rc != 0
become: true
- name: Create pipe if necessary
shell: "mkfifo {{ pipe_file }}"
when: pipe_file_test.rc != 0
become: true发布于 2021-12-19 16:17:55
命令/shell模块对幂等性有一些粗略的支持:
- name: Create named pipe
command:
cmd: mkfifo /tmp/testpipe
creates: /tmp/testpipe如果存在/tmp/testpipe,ansible将报告“无更改”。
https://stackoverflow.com/questions/70393396
复制相似问题