使用预定义的用户名和密码运行Ansible playbook任务
这是我的ansible脚本的代码使用预定义的用户名和密码运行Ansible playbook任务,ansible,Ansible,这是我的ansible脚本的代码 --- - hosts: "{{ host }}" remote_user: "{{ user }}" ansible_become_pass: "{{ pass }}" tasks: - name: Creates directory to keep files on the server file: path=/home/{{ user }}/fabric_shell state=directory - name:
---
- hosts: "{{ host }}"
remote_user: "{{ user }}"
ansible_become_pass: "{{ pass }}"
tasks:
- name: Creates directory to keep files on the server
file: path=/home/{{ user }}/fabric_shell state=directory
- name: Move sh file to remote
copy:
src: /home/pankaj/my_ansible_scripts/normal_script/installation/install.sh
dest: /home/{{ user }}/fabric_shell/install.sh
- name: Execute the script
command: sh /home/{{ user }}/fabric_shell/install.sh
become: yes
我正在使用命令运行ansible playbook>>>
ansible playbook send\u run\u shell.yml--extra vars“user=sakshi host=192.168.0.238 pass=Welcome01”
但我不知道为什么会出错
ERROR! 'ansible_become_pass' is not a valid attribute for a Play
The error appears to have been in '/home/pankaj/go/src/shell_code/send_run_shell.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- hosts: "{{ host }}"
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
请引导,我做错了什么
提前感谢…请查看此线程并单击。我建议以这种方式使用
成为用户
:
- hosts: all
tasks:
- include_tasks: task/java_tomcat_install.yml
when: activity == 'Install'
become: yes
become_user: "{{ aplication_user }}"
尝试不要使用pass=Welcome01
在与远程计算机交谈时,Ansible默认假定您使用的是SSH密钥。鼓励使用SSH密钥,但也可以在需要时通过提供选项ask pass使用密码身份验证。如果使用sudo功能,并且当sudo需要密码时,还提供--ask-been-pass(以前是--ask-sudo-pass,它已被弃用)
ansible\u been\u pass
是一个可以设置为变量的连接参数:
---
- hosts: "{{ host }}"
remote_user: "{{ user }}"
vars:
ansible_become_pass: "{{ pass }}"
tasks:
# ...
这就是说,您也可以将
remote\u user
移动到变量中(指整个变量),将其保存到单独的主机或组变量文件中,并使用进行加密。让我试试您建议我的方式@3sky.ansible playbook send\u run\u shell.yml--extra vars“user=sakshi host=192.168.0.238”--让我运行这个命令。而更改后的yaml文件正在获取错误“msg”:“无法通过ssh连接到主机:权限被拒绝(公钥、密码)。\r\n”@3sky--ask sudo pass
在您以用户身份登录(例如使用ssh密钥)并想要sudo时处于这种情况。要以普通用户身份登录,请尝试--询问密码。