Authentication 使用Ansible设置新的Junos用户

Authentication 使用Ansible设置新的Junos用户,authentication,configuration,ansible,junos-automation,Authentication,Configuration,Ansible,Junos Automation,我正在尝试为运行Junos的vMX路由器创建一个新用户。该用户需要是具有以下凭据的超级用户: 用户名:admin 密码:admin123 直接从命令行执行此操作很容易,我只需切换到编辑模式并键入以下命令 set system login user admin uid 3000 class super-user authentication plain-text-password 然后控制台会提示您输入密码,然后进行确认,因此我按如下方式输入密码 admin123 admin123 然后,我可

我正在尝试为运行Junos的vMX路由器创建一个新用户。该用户需要是具有以下凭据的超级用户:

用户名:admin

密码:admin123

直接从命令行执行此操作很容易,我只需切换到编辑模式并键入以下命令

set system login user admin uid 3000 class super-user authentication plain-text-password
然后控制台会提示您输入密码,然后进行确认,因此我按如下方式输入密码

admin123
admin123
然后,我可以提交更改,并创建用户。问题在于,当我尝试使用ansible为8个不同的vmx路由器重复此过程时。我已经建立了以下剧本:

---
- 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"
---
- 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: [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时,操作系统不知道如何处理仅包含密码的行

我还尝试了以下剧本:

---
- 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"
---
- 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为新用户设置密码,以加快在多个设备上重复此命令的过程?

它通过netconf会话进行通信。并且不是用户交互会话。因此,您可以在一个文件中获取所需的配置,并使用JUniter\u junos\u 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: merge

cat create_user.conf我不完全确定在.conf文件中需要做什么,我尝试了以下操作:
system{login{user mips{uid 3000;class super user;身份验证{plain text password“mips123”}}}
但没有成功,上述内容是正确的。问题出在剧本上,现在已经解决了!