我有生成变量 var1 和 var2 的 python 脚本
这些变量用作 Ansible playbook 的额外 var 参数。
由 python scirpt 和 playbook 动态生成的脚本变量是:
cat palybook1.yml ->
- hosts: localhost tasks:
- name: "CV: Publish New Versions" katello_content_view_version: username: "{{ username }}" password: "{{ password }}" server_url: "{{ server_url }}" validate_certs: "{{ validate_certs }}" organization: "{{ item.org }}" content_view: "{{ item.cv }}" loop: "{{ cvlist }}"
cat palybook2.yml ->
- hosts: localhost tasks:
- name: "CV: Publish New Versions" katello_content_view_version: username: "{{ username }}" password: "{{ password }}" server_url: "{{ server_url }}" validate_certs: "{{ validate_certs }}" organization: "{{ item.org }}" content_view: "{{ item.cv }}" loop: "{{ cvlist }}"
vars1 和 vars2 由 python 脚本生成。
cat vars1 ->
server_url: "https://www.example1.com" certs: true cvlist:
- { org: 'ORG1',cv: 'cv1' }
- { org: 'ORG2',cv: 'cv2' }
- { org: 'ORG3',cv: 'cv3' }
- { org: 'ORG4',cv: 'cv4' }
- { org: 'ORG5',cv: 'cv5' }
cat vars2 ->
server_url: "https://www.example2.com" certs: true cvlist:
- { org: 'ORG6',cv: 'cv1' }
- { org: 'ORG7',cv: 'cv2' }
- { org: 'ORG8',cv: 'cv3' }
- { org: 'ORG9',cv: 'cv4' }
- { org: 'ORG10',cv: 'cv5' }
我需要以下单个剧本:
python3 script.py --host server1.example.com --cycle dev --user user1
--password password1 > vars1 ansible-playbook playbook1.yml --extra-vars "@vars1" --extra-vars "username=user1 password=password1"
python3 script.py --host server2.example.com --cycle dev --user user1
--password password1 > vars2 ansible-playbook playbook2.yml --extra-vars "@vars2" --extra-vars "username=user1 password=password1"
正如你所看到的 script.py 和 playbook1/2.yml 使用了两次
我想在一个剧本中使用上面的 python 脚本和 playbook1/2 。
有人可以告诉我是否可以在单个剧本中运行 python 脚本和多个剧本