我必须使用 ansible 创建多个用户。我在 vars 部分的 ansible play 中将用户作为列表传递:
vars:
users: ['user1', 'user2']
Run Code Online (Sandbox Code Playgroud)
然后我必须创建一个使用该用户 ID 作为参数的脚本。脚本中的命令是这样的:
blobfuse $1 --tmp-path=/mnt/resource/{{ item }}/ -o attr_timeout=240 -o entry_timeout=240 -o negative_timeout=120 -o uid=$USER_ID -o allow_other --container-name={{ item }} --file-cache-timeout-in-seconds=120 --config-file=/root/connection-{{ item }}.cfg
一切正常,除了uid= 我已经尝试使用查找的管道插件,但这并没有让我获得正确的 UID:
{{ lookup('pipe', 'grep -w {{ item }} /etc/passwd | cut -d : -f3') }}
我的最终目标是获取每个创建的用户的 UID,并将其传递给上面的 blobfuse 命令。