【问题标题】:Using Ansible to set new Junos OS User使用 Ansible 设置新的 Junos OS 用户
【发布时间】:2020-02-15 14:40:20
【问题描述】:

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

用户名:管理员

密码: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"

但这返回了以下错误:


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 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 为新用户设置一个密码来加快在多个设备上重复它的过程?

【问题讨论】:

    标签: authentication configuration ansible junos-automation


    【解决方案1】:

    它通过 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: merge
    

    cat create_user.conf

    system {
        -----
    }
    

    如果您需要进一步的帮助,请告诉我。

    【讨论】:

    • 我不完全确定 .conf 文件中需要包含什么我尝试了这个:system { login { user mips { uid 3000; class super-user; authentication { plain-text-password "mips123" } } } } 但没有成功
    • 以上是正确的。问题出在已修复的剧本上!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-21
    • 1970-01-01
    • 2020-01-05
    • 1970-01-01
    • 2017-07-05
    相关资源
    最近更新 更多