特定任务的 Ansible-Playbook 传递列表
Ansible-Playbook passing lists for specific tasks
Much like this question regarding passing an array mine is a bit different
OP 试图让该剧在 运行 上播放多个主机。
明显失败。我的目标是 "loop" 通过我在 .boto
配置文件中每个帐户的游戏。当然,我可以利用一个简单的 bash 循环。但是正在考虑通过将特定的 "acct" 变量传递给它来使用 Ansible 做更多的事情。 *更新失败的任务。
- name: Ansible Roles in AWS .v01
hosts: 127.0.0.1
gather_facts: no
connection: local
vars:
role_state: present
dict1: { "dev", "mgmt", "uat", "sbx" }
# - debug: var=
tasks:
- name: hhc-ADMIN-Role-Create
with_items: dict1
tags:
- admin
iam:
iam_type: role
region: us-east-1
profile: "{{ item }}"
name: hhc-{{ dict1 }}-ADMIN
state: "{{role_state}}"
trust_policy_filepath: ./Policies/Trust/Role-Trust-Policy.json
一个想法是在循环中设置 AWS_PROFILE
环境变量。
伪代码:
tasks:
- ec2: ... ....
environment:
AWS_PROFILE: "{{item}}"
with_items: cli_var
使用 "list" 的一种方法如下:
---
- name: Ansible Roles in AWS .v01
hosts: 127.0.0.1
gather_facts: no
connection: local
vars:
role_state: present
list:
- { profile: "dev", role: "ADMIN" }
- { profile: "dev", role: "MGMT" }
tasks:
- name: hhc-ADMIN-Role-Create
with_items: "{{ list }}"
tags:
- admin
iam:
iam_type: role
region: us-east-1
profile: "{{ item.profile }}"
name: hhc-{{ item.profile }}-{{ item.role }}
state: "{{role_state}}"
trust_policy_filepath: ./Policies/Trust/Role-Trust-Policy.json
这将在 Dev 中创建 ADMIN 和 MGMT 角色。必须有一种更优雅的方式来做像
这样的事情
list:
- { profile: "dev", role: [ "ADMIN", "MGMT"] }
Much like this question regarding passing an array mine is a bit different
OP 试图让该剧在 运行 上播放多个主机。
明显失败。我的目标是 "loop" 通过我在 .boto
配置文件中每个帐户的游戏。当然,我可以利用一个简单的 bash 循环。但是正在考虑通过将特定的 "acct" 变量传递给它来使用 Ansible 做更多的事情。 *更新失败的任务。
- name: Ansible Roles in AWS .v01
hosts: 127.0.0.1
gather_facts: no
connection: local
vars:
role_state: present
dict1: { "dev", "mgmt", "uat", "sbx" }
# - debug: var=
tasks:
- name: hhc-ADMIN-Role-Create
with_items: dict1
tags:
- admin
iam:
iam_type: role
region: us-east-1
profile: "{{ item }}"
name: hhc-{{ dict1 }}-ADMIN
state: "{{role_state}}"
trust_policy_filepath: ./Policies/Trust/Role-Trust-Policy.json
一个想法是在循环中设置 AWS_PROFILE
环境变量。
伪代码:
tasks:
- ec2: ... ....
environment:
AWS_PROFILE: "{{item}}"
with_items: cli_var
使用 "list" 的一种方法如下:
---
- name: Ansible Roles in AWS .v01
hosts: 127.0.0.1
gather_facts: no
connection: local
vars:
role_state: present
list:
- { profile: "dev", role: "ADMIN" }
- { profile: "dev", role: "MGMT" }
tasks:
- name: hhc-ADMIN-Role-Create
with_items: "{{ list }}"
tags:
- admin
iam:
iam_type: role
region: us-east-1
profile: "{{ item.profile }}"
name: hhc-{{ item.profile }}-{{ item.role }}
state: "{{role_state}}"
trust_policy_filepath: ./Policies/Trust/Role-Trust-Policy.json
这将在 Dev 中创建 ADMIN 和 MGMT 角色。必须有一种更优雅的方式来做像
这样的事情list:
- { profile: "dev", role: [ "ADMIN", "MGMT"] }