当运行带有多个“ -i”的ansible-playbook时,将忽略第一个清单文件

时间:2019-07-09 16:03:30

标签: ansible

当像下面那样运行时,Ansible-playbook似乎会忽略第一个清单文件。它只能识别最后一个文件。

您能否建议如何使其在两个服务器上运行?我正在运行ansible-playbook 2.3.2.0

ansible-playbook -i test1.infrastructure  -i test2.infrastructure deploy_server.yml
PLAY [all] *********************************************

TASK [Gathering Facts] *********************************************
ok: [test2]

TASK [Get release package] *********************************************
 [WARNING]: Consider using unarchive module rather than running tar

changed: [test2]

TASK [Set latest_sourcetree] *********************************************
ok: [test2]
...

以下是清单文件的示例

test1.infrastructure

##################
[test1]
##################
test1hostname
[test1:vars]
# Database
db_server=dbservername
dbschema=test1schema
oracle_sid=test1sid
oracle_port=1521
...

test2.infrastructure

##################
[test2]
##################
test2hostname
[test2:vars]
# Database
db_server=dbservername
dbschema=test2schema
oracle_sid=test2sid
oracle_port=1521
...

deploy_server.yml

  - hosts: all
  pre_tasks:
  - name: Get directory name in server release package
    shell: tar -tzf "{{server_release_package}}" | head -1 | sed -e 's/\/.*//'
    register: server_code_dir

  - name: Set latest_sourcetree variable = "{{server_root_dir}}/{{server_code_dir.stdout}}"
    set_fact:
      latest_sourcetree: "{{server_root_dir}}/{{server_code_dir.stdout}}"

  roles:
   - deploy_source_tree

deploy_source_tree / tasks / main.yml


- name: Create directory {{latest_sourcetree}}
  file:
    path={{latest_sourcetree}}
    state=directory

- name: Unpack server release package to {{latest_sourcetree}}
  unarchive:
    src: "{{server_release_package}}"
    dest: "{{server_root_dir}}"
    remote_src: yes

- name: Write runtime properties file
  template:
    src: "{{playbook_dir}}/environments/{{client_id}}/{{env_id}}/files/server.runtime.properties"
    dest: "{{latest_sourcetree}}/conf/server.runtime.properties.{{dbschema}}"

- name: Generate Cshrc file
  shell: cd {{latest_sourcetree}}/conf/ ; ./generate.sh -p server.runtime.properties.{{dbschema}} -b -d -t -o Cshrc.{{dbschema}}

- name: Replace new Cshrc file
...

编辑-@itiic的建议有效,将清单文件放在目录中并使用“ -i dirname”运行,我仍然很好奇为什么使用多个-i不起作用,如果有人可以建议的话,我真的很感激

0 个答案:

没有答案