小编Jea*_*REY的帖子

如何在循环中使用with_dict编写Ansible任务(with_items)

我想更新INI配置文件.

今天,我以这种方式将我的信息存储在var文件中(在group_vars中):

# Identity configuration information
identity_servers_conf:
  DEFAULT:
    admin_token: "{{identity_admin_token}}"
    verbose: True
  database:
    connection: "mysql://{{ identity_db_user }:{{ identity_db_password }}@{{ db_lb_name }}/{{ identity_db }}"    
  token:
    provider: keystone.token.providers.uuid.Provider
    driver: keystone.token.persistence.backends.sql.Token  
Run Code Online (Sandbox Code Playgroud)

在我的Ansible任务中,我以这种方式使用这些信息:

- name: configuration / modify keystone.conf ini file DEFAULT section
  ini_file:
    section: DEFAULT
    dest: /etc/keystone/keystone.conf
    option: "{{item.key}}"
    value: "{{item.value}}"
  with_dict: identity_servers_conf['DEFAULT']
Run Code Online (Sandbox Code Playgroud)

有没有办法用每个"section"参数迭代我的dict文件,即DEFAULT,数据库,令牌.事实上,我试图找到一种方法来执行嵌入在with_items循环中的with_dict.

python ini configuration-files ansible

6
推荐指数
1
解决办法
5056
查看次数

如何使用 Ansible 或 Jinja2 在变量名中转义冒号(“:”)?

我使用 Ansible 模块os_networks_facts获取 Openstack 网络信息。

此模块以 openstack_networks 结构返回信息:

    "openstack_networks": [
    {
        "admin_state_up": true,
        "id": "5632dc44-dbda-4752-8155-fe782e95cc29",
        "mtu": 0,
        "name": "public_RSC",
        "port_security_enabled": true,
        "router:external": true,
        "shared": false,
        "status": "ACTIVE",
        "subnets": [
            "7b07432c-f0a0-415a-8b28-7e87918cc6d4",
            "a56e25cb-0710-4a64-869e-4af2d5bf9c64",
            "c4ff60af-44bc-4252-ab38-fd242d51f0f2"
        ],
        "tenant_id": "6025f8013cee46c093cb97cb36a1a86e"
    },
    {
        "admin_state_up": true,
        "id": "7812f951-4bc9-41c0-9db2-1f49b8a7ee47",
        "mtu": 0,
        "name": "kuby-network",
        "port_security_enabled": true,
        "router:external": false,
        "shared": false,
        "status": "ACTIVE",
        "subnets": [
            "6ad9ce9b-ba54-4d74-bbb6-8dfc50526eff"
        ],
        "tenant_id": "a9cffc26ba5a4a8e883f04dc7180a91d"
    }
]
Run Code Online (Sandbox Code Playgroud)

我想对“路由器:外部”属性的值进行测试。但是,该属性的名称中包含一个冒号。

当我尝试在 Ansible 中打印它时:

- hosts: localhost
  connection: local
  gather_facts: false

  tasks:
    - name: get network information …
Run Code Online (Sandbox Code Playgroud)

escaping character jinja2 openstack ansible

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