如何解决如何在Ansible剧本中的用户给定主机上运行用户给定命令?
---
- name: Adding the host server
hosts: localhost
vars_prompt:
- name: "Server"
prompt: "Server IP"
private: no
- name: "User"
prompt: "Username"
default: "Ubuntu"
private: no
- name: "Passwd"
prompt: "Password"
private: yes
encrypt: "sha512_crypt"
- name: "IdFile"
prompt: "Identity file path(~/.ssh/id_rsa.pub)"
private: no
when: Passwd is undefined
- name: "cmd"
prompt: "Which command you want to run 1.ls -l 2.Top 3.uptime."
private: |-
no
tasks:
- name: Add host server
add_host:
name: "{{ Server }}"
ansible_ssh_user: "{{ User }}"
ansible_ssh_private_key_file: "{{ IdFile }}"
when: IdFile is defined
- name: Add host server
add_host:
name: "{{ Server }}"
ansible_ssh_user: "{{ User }}"
ansible_ssh_pass: "{{ Passwd }}"
when: Passwd is defined
- name: check OS name
shell: uname -a
delegate_to: "{{ Server }}"
- hosts: "{{ Server }}"
#below are for testing only.
tasks:
- name: Execute a command using the shell module
become: true
#become_user: root
shell: uname -a
- name: check OS name
shell: uname -a
delegate_to: "{{ Server }}"
这是以下错误: 致命的:[本地主机]:不可更改! => {“更改”:false,“ msg”:“身份验证失败。”,“无法访问”:true}
有人可以检查一下上面的代码并提出更改建议吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。