gpt4 book ai didi

ansible - 使用预定义的用户名和密码运行 Ansible playbook 任务

转载 作者:行者123 更新时间:2023-12-02 21:23:29 26 4
gpt4 key购买 nike

这是我的 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: 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_run_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 }}"

请指导,我做错了什么。

提前致谢...

最佳答案

ansible_become_pass 是一个连接参数,您可以将其设置为变量:

---
- hosts: "{{ host }}"
remote_user: "{{ user }}"
vars:
ansible_become_pass: "{{ pass }}"
tasks:
# ...

也就是说,您也可以将 remote_user 移动到变量(引用整个 list of connection parameters ),将其保存到单独的 host_vars- 或 group_vars-文件中,并使用 Ansible Vault 进行加密。 .

关于ansible - 使用预定义的用户名和密码运行 Ansible playbook 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51871051/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com