2017-07-08 49 views
1

因此,我使用Ansible每天管理我们的AWS实例,现在我正在测试管理我们的网络基础设施(我是网络人员,谁可以做一些系统管理员的东西),但遇到了一个我似乎无法解决的问题。无法打开外壳:Ansible v2.3.1.0

我有一个Cisco 3750G在这里,我已经启用了SSH。我可以使用指定的用户ssh并运行我的剧本中失败的所有命令。

我能成功地使用ping模块从Ansible这个开关,但每当我尝试使用ios_commandsios_configs模块,它失败,出现错误unable to open shell

我使用Ansible v2.3.1.0,它具有持久连接作为新功能。做了一些谷歌搜索,我发现有几个人有这个问题,并以各种方式修复它(这些都没有为我工作)。

事情我已经尝试:

  • secrets.yaml文件中指定的连接变量。 然后在秘密文件中使用我的用户名,auth_pass和密码 指定provider
  • ansible.cfg文件

更改ansible_connection设置localssh(既不 工作)

  • 现在残疾人host_key_checking没有工作我试过后: - 手动创建的供应商连接变量playbook 本身。 - 使用2个不同的模块ios_commandsios_configs(有2个模块之间,但为我用两者都应该采取同样的一些
    差)

    https://docs.ansible.com/ansible/network_debug_troubleshooting.html#category-unable-to-open-shell 该文档指出,我看到的错误通常是一个身份验证问题但这似乎并非如此。

    其他人碰到这个或有任何见解? 我有一个日志文件,包含我的playbook运行的调试输出,如果有人想查看。 我已经发布了我的示例剧本以供审阅。

    主机:开关 gather_facts:没有 连接:本地 任务:

    - name: GATHER CREDENTIALS 
        include_vars: secrets.yaml 
    
    - name: DEFINE CONNECTION PROVIDER 
        set_fact: 
        provider: 
         username: "{{ creds['username'] }}" 
         password: " {{ creds['password'] }}" 
         auth_pass: "{{ creds['auth_pass'] }}" 
    
    - name: Show interfaces 
        ios_config: 
        provider: "{{ provider }}" 
        commands: 
         - show ip int br 
        register: cisco_int 
    
    - debug: var=cisco_int.stdout_lines 
    
  • +0

    所以我仍然无法使用该版本的Ansible得到这个工作。我将尝试安装它的较旧版本(没有持久连接功能)并查看是否有效。 –

    回答

    2

    我终于想通了什么事在这里。 这是一个事物的组合。

    • 的2.3持续连接功能打破了我,所以我不得不 降级到2.2.0.0

    • 然后我不得不手动指定我的库存我的Python解释器。 显然你可以安装paramiko的方式,不会将它安装到 /usr/bin/python,而是去/usr/local/bin/python,前者 是Ansible运行其模块的地方。

    • 我也认为错误的行为ios_commandios_config 是类似的。 config用于全局/接口配置 模式中的命令。 command从用户和priv执行模式运行。现在

    我的剧本跑,我可以得到的show ip int br输出上我的3750

    0

    我知道你说你降级。如果你决定给2.3另一个镜头,也许这会有所帮助。当我从2.2移动到2.3时,我遇到了相同的问题。我正在使用以下格式运行我的基本操作手册。虽然在我的TACACS设置中我没有使用启用密码,但我包含了该选项。

    主机

    [ios:vars] 
    ansible_python_interpreter=/usr/bin/python 
    ansible_connection = local 
    # If SSH/ For Telnet - Port=23 
    port=22 
    [ios] 
    ios-swt-1 
    ios-rtr-1 
    

    secrets.yml

    --- 
    creds: 
    username: ansible 
    password: '@ns1Bl3' 
    #Uncomment For Enable: 
    #auth_pass: [email protected] 
    

    剧本

    --- 
    - hosts: ios 
        gather_facts: no 
        connection: local 
    
        tasks: 
    
        - name: obtain login credentials 
        include_vars: secrets.yml 
    
        - name: define provider 
        set_fact: 
         provider: 
         host: "{{ inventory_hostname }}" 
         username: "{{ creds['username'] }}" 
         password: "{{ creds['password'] }}" 
         #Uncomment next line if enable password is needed 
         #auth_pass: "{{ creds['auth_pass'] }}" 
         transport: cli 
    
        - include: tasks/ios_command-freeform.yml 
    

    任务/ ios_command-freeform.yml

    --- 
    - name: Freeform Task 
        ios_command: 
        provider: "{{ provider }}" 
        commands: 
    # Change the command after "-" to any IOS command you would like to run. 
         - show version 
        register: freeform 
    
    # Provides an output if -vvv is not used when running ansible-playbook 
    - debug: var=freeform.stdout_lines 
    
    - name: append to output 
    # append the command output to a local file 
        copy: 
        content: "{{ freeform.stdout[0] }}" 
        dest: "play_results/{{ inventory_hostname }}.txt" 
    
    +0

    嗯不要以为这是可能的在我的环境。启用密码是一切:P尽管我确实在最新版本的ansible中看到了对networkcli模块的一些更改。也许生病再给它一次.... –