小编qia*_*ang的帖子

我如何使用Ansible嵌套变量?

我有一个像下面这样的Ansible剧本,我想使用这样的嵌套变量: msg={{{{Component}}.community_release_num}},但是当我运行playbook时:

ansible-playbook vartest.yml -e 'version=version_402', it not work 

[es@vpn-server nested-var]$ tree
.
??? vars
?   ??? horizon.yml
?   ??? version_402.yml
??? vartest.yml

1 directory, 3 files
[es@vpn-server nested-var]$ cat vartest.yml 
---

- name: test 
  hosts: localhost
  vars_files:
    - vars/{{version}}.yml
  tasks:
    - debug: msg={{{{Component}}.community_release_num}}
    - debug: msg={{{{Component}}.release_num}}

[es@vpn-server nested-var]$ cat vars/horizon.yml 
Component: horizon

[es@vpn-server nested-var]$ cat vars/version_402.yml 
- horizon:
   community_release_num: '9.0.1'
   release_num: '4.0.2'
[es@vpn-server nested-var]$
Run Code Online (Sandbox Code Playgroud)

错误消息

[es@vpn-server nested-var]$ ansible-playbook vartest.yml -e 'version=version_402'
/usr/lib64/python2.6/site-packages/cryptography/__init__.py:25: DeprecationWarning: Python 2.6 is no longer …
Run Code Online (Sandbox Code Playgroud)

jinja2 ansible

11
推荐指数
1
解决办法
2万
查看次数

如何控制ansible中rescue模块的执行

我有一个像下面这样的剧本,我想在块出错时控制救援的执行\xe3\x80\x82\n我在when: is_debug is defined救援\xef\xbc\x8c之后添加,但是当我运行时ansible-playbook dashboard.yml ,不给出is_debug值,救援是当块有错误时仍然执行。

\n\n

我想知道如何控制ansible中rescue模块的执行?

\n\n
[root@ansiable-test update]# cat dashboard.yml\n---\n- hosts: controller\n  vars_files:\n        - "vars/vars.yml"\n  tasks:\n    - name: update horizon\n    - block:\n        - include: "roles/dashboard/tasks/update-horizon.yml"\n      rescue:\n      when: is_debug is defined\n        - debug: msg=\'An error occurred during the upgrade,roll back to the old version\'\n        - include: "roles/dashboard/tasks/rollback.yml"\n
Run Code Online (Sandbox Code Playgroud)\n

ansible

4
推荐指数
1
解决办法
7192
查看次数

标签 统计

ansible ×2

jinja2 ×1