我正在编写一个Ansible脚本,它应该在运行Debian或CentOS的每个主机上更新openssl.在主机上,我们的SSH密钥是为我自己的用户或 root 用户存放的.我想检查我的用户是否存在于主机上,如果不是,我想要与root用户进行身份验证.有可能这样做吗?我尝试使用bash命令,但我想在运行任务之前检查我的用户是否存在.也许我的问题有其他解决方案,但我不知道.运行此playbook会引发语法错误.我的脚本现在看起来像这样:
---
- hosts: "{{ host_group }}"
remote_user: "{{ username }}"
tasks:
# Check whether there's a existinig user or whether you have to use root
- name: Check whether there's your user on the machine
action: shell /usr/bin/getent passwd $username | /usr/bin/wc -l | tr -d ''
register: user_exist
remote_user: root
when: user_exist.stdout == 0
tags:
- users
# Install openssl on Ubuntu or Debian
- name: Install openssl on Ubuntu or Debian
become: …Run Code Online (Sandbox Code Playgroud)