来自包含

时间:2017-11-09 23:24:49

标签: ansible cisco

Unable to open shell: Ansible v2.3.1.0升级

我遇到了,

  

[DEPRECATION WARNING]:包含是为了向后兼容而保留,但不鼓励使用。模块文档       详细信息页面可能会解释有关此基本原理的更多信息。此功能将在以后的版本中删除。弃用       可以通过在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]# 

1 个答案:

答案 0 :(得分:1)

Ansible告诉您include指令已被弃用,并且在以后的版本reference中无法使用:

  

包含 - 包含播放或任务列表。

     

<强> DEPRECATED

     

包含动作太混乱,处理游戏和任务,既动态又静态。该模块将在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