【问题标题】:ansible (include_vars) from include来自包含的 ansible (include_vars)
【发布时间】:2017-11-09 23:24:49
【问题描述】:

Unable to open shell: Ansible v2.3.1.0升级

我遇到了,

[弃用警告]:保留包含是为了向后兼容,但不鼓励使用。模块文档 详细信息页面可能会解释有关此基本原理的更多信息。此功能将在以后的版本中删除。弃用 可以通过在 ansible.cfg 中设置 deprecation_warnings=False 来禁用警告。

来自

---
- 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

使用include_vars 涉及文件夹内容的正确方法是什么? (尝试改用它,但 "tasks" 中的 yml-s 最终被主要游戏忽略)。

提前致谢

[root@ymlhost-3 ansible-yml]# cat cisco-play.yml 
---
- name: cisco-yml
  hosts: cisco
  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'] }}"
        auth_pass: "{{ creds['auth_pass'] }}"
        authorize: yes

  - name: Include all .yml
    include_vars:
      dir: 'tasks'
      extensions:
          - json
          - yml
[root@ymlhost-3 ansible-yml]# 

也尝试了不同的形式

[root@ymlhost-3 ansible-yml]# cat cisco-play.yml 
---
- name: cisco-yml
  hosts: cisco
  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'] }}"
        auth_pass: "{{ creds['auth_pass'] }}"
        authorize: yes

  - name: Include all .yml files except bastion.yml (2.3)
    include_vars:
      dir: 'vars'
      ignore_files: 'bastion.yml'
      extensions: ['yml']
[root@ymlhost-3 ansible-yml]# 

【问题讨论】:

  • 有什么问题,有什么问题,include的代码在哪里?包含变量与它无关,您正在对代码的错误部分进行故障排除。
  • 已更新。如果我切换回旧的包含语句,它可以工作。但较新的没有
  • 大约 90% 的问题与问题无关。剩下的部分可以通过花一分钟时间思考警告的含义来解决,而不是在黑暗中开枪。

标签: ansible cisco


【解决方案1】:

Ansible 告诉您 include 指令已被弃用,并且在未来的版本中将无法使用,reference

包括 - 包括一个游戏或任务列表。

已弃用

包含动作太混乱了,既要处理游戏又要处理任务,既是动态的又是静态的。该模块将在 2.8 版中删除。作为替代方案,使用 include_tasks、import_playbook、import_tasks。


替换:

- include: tasks/ios_command-freeform.yml

与:

- import_tasks: tasks/ios_command-freeform.yml

或者:

- include_tasks: tasks/ios_command-freeform.yml

此处解释了差异:Differences Between Static and Dynamic。您的用例可能没有区别,因此请使用import_tasks

【讨论】:

  • 效果很好。感谢您的时间。我应该更仔细地用谷歌搜索
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-02
  • 2022-08-18
  • 1970-01-01
  • 2015-07-23
  • 2019-05-01
  • 2015-05-02
相关资源
最近更新 更多