background:
There are a group of hosts deploying k8s services, but they are not given root permissions. Dozens of hosts cannot be manually deployed one by one, you must use ansible. It saves time and improves work efficiency.
Steps:
- First add the information of ordinary users in the ansible.cfg configuration file, please see the screenshot below
Open the comment on privilege escalation, as shown in the figure
[privilege_escalation]
become=True ***//Use "true" or "yes" to indicate that this privilege is enabled, such as: become=true indicates that the ******* became switch is turned on.
become_method=sudo *//******** indicates how to switch the ordinary account to root or other required accounts. You can use su or sudo here. *
become_user=root *//******** is set to the root account, which is equivalent to when we log in to the remote host as a normal account, and then use su-root to switch to the root account. *
become_ask_pass=True *// means asking for password*
2. Execute this command on the command line:
ansible nlp -m shell -a'systemctl reload docker' -K can use ordinary users to execute commands