我想将文件的brew医生结果解析为一个可识别的var列表
Brew Doctor提供以下内容
Warning: The following directories are not writable by your user:
/usr/local/Cellar
/usr/local/Homebrew
/usr/local/bin
/usr/local/etc
/usr/local/etc/bash_completion.d
/usr/local/include
/usr/local/lib...
You should change the ownership of these directories to your user.
sudo chown -R $(whoami) /usr/local/Cellar /usr/local/Homebrew...
我想存储这些文件并在ansible中遍历它们
答案 0 :(得分:1)
这是您要找的吗?
vars:
my_command: Brew-Doctor-List-Files-Command
my_owner: Brew-Doctor-Files-Owner
my_dirs: []
tasks:
- set_fact:
my_dirs: "{{ my_dirs + [ item ] }}"
with_lines: "{{ my_command }}"
when: item is search('^/usr/local/(.*)')
- file:
state: directory
recurse: yes
path: "{{ item }}"
owner: "{{ my_owner }}"
loop: "{{ my_dirs }}"
(未经测试)
答案 1 :(得分:0)
已解决:
vars:
my_dirs: []
tasks:
- name: set_fact IGNORE ERRORS
shell: brew doctor
register: doc_data
ignore_errors: yes
- name: setting facts for chown and chmod from brew doctor
set_fact:
my_dirs: "{{ my_dirs + [ item ] }}"
with_items: "{{ doc_data.stderr_lines }}"
when: item | regex_search('^/usr/local/(.*)')