gpt4 book ai didi

Ansible主机文件如何在ansible_ssh_pass中提供#

转载 作者:行者123 更新时间:2023-12-05 05:39:59 33 4
gpt4 key购买 nike

我是ansible的新手。我在主机文件中遇到问题。错误输出如下。

我的问题是:如何转义 ansible_ssh_pass 中的#。

我尝试使用 ansible_ssh_pass="airtel\#121"和 ansible_ssh_pass=airtel\#121 两种方式都没有双引号。它正在抛出错误。

ansible版本:ansible-playbook 2.9.6

主机文件条目如下:

[设备]10.10.10.10 ansible_ssh_user="abcd"ansible_ssh_pass="airtel#121"

剧本如下:

- name: Cisco show version example
hosts: devices
gather_facts: false

ansible_connection: ansible.netcommon.network_cli
ansible_network_os: cisco.ios.ios
ansible_become: yes
ansible_become_method: enable

tasks:
- name: run show version on the routers
ios_command:
commands:
- show version
register: output

- name: print output
debug:
var: output.stdout_lines

报错如下。

xxxx@xxxx:/etc/ansible/playbooks# ansible-playbook check_connectivity_temp.yml -vvvv
ansible-playbook 2.9.6
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python3/dist-packages/ansible/plugins/callback/default.py

PLAYBOOK: check_connectivity_temp.yml ***************************************************************************************
Positional arguments: check_connectivity_temp.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/etc/ansible/hosts',)
forks: 5
1 plays in check_connectivity_temp.yml

PLAY [Cisco show version example] *******************************************************************************************
META: ran handlers

TASK [run show version on the routers] **************************************************************************************
task path: /etc/ansible/playbooks/check_connectivity_temp.yml:14
<10.10.10.10> attempting to start connection
<10.10.10.10> using connection plugin ansible.netcommon.network_cli
<10.10.10.10> local domain socket does not exist, starting it
<10.10.10.10> control socket path is /root/.ansible/pc/aaec916454
<10.10.10.10> local domain socket listeners started successfully
<10.10.10.10> loaded cliconf plugin ansible_collections.cisco.ios.plugins.cliconf.ios from path /root/.ansible/collections/ansible_collections/cisco/ios/plugins/cliconf/ios.py for network_os cisco.ios.ios
<10.10.10.10> ssh type is set to auto
<10.10.10.10> autodetecting ssh_type
[WARNING]: ansible-pylibssh not installed, falling back to paramiko
<10.10.10.10> ssh type is now set to paramiko
<10.10.10.10>
<10.10.10.10> local domain socket path is /root/.ansible/pc/aaec916454
fatal: [10.10.10.10]: FAILED! => {
"changed": false,
"msg": "Failed to authenticate: Authentication failed."
}

PLAY RECAP ******************************************************************************************************************
10.10.10.10 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

我的问题是:如何转义 ansible_ssh_pass 中的#。

最佳答案

将散列字符“#”放入表达式 {{ '#' }}。例如,

    - debug:
var: ssh_pass
vars:
ssh_pass: "airtel{{ '#' }}121"

给予

  ssh_pass: airtel#121

关于Ansible主机文件如何在ansible_ssh_pass中提供#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72528148/

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