我试图为运行Junos的vMX路由器创建一个新用户。用户需要是具有以下凭据的超级用户:
用户名: admin
密码: admin123
直接从命令行执行此操作非常简单,我只需更改为编辑模式并键入以下命令
set system login user admin uid 3000 class super-user authentication plain-text-password控制台然后提示您输入密码,然后确认密码,因此我输入密码如下
admin123
admin123然后我可以提交更改,并且已经创建了用户。问题在于,当我试图重复这个过程时,8种不同的vmx路由器使用ansible。我已设置了下列剧本:
---
- name: Create admin user
hosts: newvmx
roles:
- Juniper.junos
connection: local
gather_facts: no
tasks:
- name: create new user
juniper_junos_config:
config_mode: "private"
load: "set"
lines:
- "set system login user admin123 uid 3000 class super-user authentication plain-text password"
- "admin123"
- "admin123"但是这返回了以下错误:
PLAY [Create admin user] ***************************************************************************************************************************************************************************************
TASK [create new user] **************************************************************************************************************************************************************************************
fatal: [vMX6]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "msg": "Failure loading the configuraton: ConfigLoadError(severity: error, bad_element: plain-text, message: error: syntax error\nerror: unknown command\nerror: unknown command)"}我假设这与命令的最后部分有关,因为在机器上直接执行此操作时,会提示用户输入密码,因此当行由ansible传递时,OS不知道如何处理只包含密码的行。
我还尝试了以下的剧本:
---
- name: Create admin user
hosts: newvmx
roles:
- Juniper.junos
connection: local
gather_facts: no
tasks:
- name: create new user
juniper_junos_config:
config_mode: "private"
load: "set"
lines:
- "set system login user admin uid 3000 class super-user authentication plain-text password admin123"但这会导致下面的语法错误。所以这不是一次成功的尝试。
PLAY [Create admin user] ***************************************************************************************************************************************************************************************
TASK [create new user] **************************************************************************************************************************************************************************************
fatal: [vMX10]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "msg": "Failure loading the configuraton: ConfigLoadError(severity: error, bad_element: plain-text, message: error: syntax error)"}那么,有什么方法可以传递这个命令来创建一个新用户并为新用户设置一个密码,使用ansible来加快多个设备重复它的过程呢?
发布于 2019-10-18 15:38:04
它在netconf会议上相互联系。而不是用户交互会话。因此,您可以在文件中获得重新配置并加载它,并使用juniper_junos_config
- name: create user
hosts: all
roles:
- Juniper.junos
connection: local
gather_facts: no
tasks:
- name: Change Password
juniper_junos_config:
host: "{{ ansible_ssh_host }}"
port: "{{ ansible_ssh_port }}"
user: user1
passwd: "{{ passwd }}"
file: create_user.conf
load: mergecat create_user.conf <<<根据需要的配置定义。
system {
-----
}如果你需要进一步的帮助,请告诉我。
https://stackoverflow.com/questions/58453571
复制相似问题