ansible - named pipe (mkfifo) - best practice?

Viewed 263

I want to create a named pipe with ansible on Linux/Debian. In a shell script I would use the command mkfifo for creating a pipe. Now I'm wondering if there's an builtin module approach but I can't find anything in the builtin modules of ansible. Googling the question also doesn't yield any meaningful results.

My approach would be just to execute a shell command with ansible and execute mkfifo like this for example:

 - name: Create named pipe
   shell: "mkfifo testpipe"

However, to be precisely, I need to check if the pipe already exists, and if yes, I need to check filetype and so on and so on...

I bet there is a convenient way but I just can't find it.

Thank you very much for your help

Edit: I just did it this way now. I bet there are some cases I haven't catched.

- 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
1 Answers

command/shell modules have some crude support for idempotency:

 - name: Create named pipe
   command:
     cmd: mkfifo /tmp/testpipe
     creates: /tmp/testpipe

If /tmp/testpipe exists, ansible will report 'no changed'.

Related