我有多个任务,我想在一个不同的角色中包含多个时间来执行重复的任务(或重用代码),并在变量中定义这些操作。
这是变量文件[common-vars / common_vars.yml]:
STAGE_SUCCESS: "{{ playbook_dir }}/common-stages-tasks/stage_success.yml"
STAGE_FAILED: "{{ playbook_dir }}/common-stages-tasks/stage_failed.yml"
AWS_STS_ASSUME: "{{ playbook_dir }}/common-stages-tasks/aws_sts_assume.yml"
FLIP_IP: "{{ playbook_dir }}/common-stages-tasks/flip_ip.yml"
Playbook文件[playbooks / abc / site.yml]:
- hosts: abc
remote_user: ec2-user
vars_files:
- ../../common-vars/common_vars.yml
roles:
- { role: roles/common/pre-check }
- { role: roles/common/pre-audit }
- { role: roles/common/download }
- { role: roles/dsc/pre-backup }
- { role: roles/dsc/backup }
这是我的目录结构:
├── ansible.cfg
├── common-vars
│ ├── common_vars.yml
│ └── credentials.yml
├── environments
│ ├── preprod
│ │ ├── group_vars
│ │ │ └── all
│ │ └── hosts
│ ├── prod
│ │ ├── group_vars
│ │ │ └── all
│ │ └── hosts
│ └── test-env
├── playbooks
│ ├── common-stages-tasks
│ │ ├── audit_task.yml
│ │ ├── aws_sts_assume.yml
│ │ ├── dsc_db_service.yml
│ │ ├── start_service.yml
│ │ ├── fetch_swupgrade_logs.yml
│ │ ├── flip_ip.yml
│ │ ├── log_file_creation.yml
│ │ ├── notification_start.yml
│ │ ├── notification_stop.yml
│ │ ├── stage_failed.yml
│ │ ├── stage_success.yml
│ │ ├── sub_job_id_creation.yml
│ │ └── viewpoint_service.yml
│ ├── def
│ │ ├── site.yml
│ │
│ ├── abc
│ │ ├── site.yml
│ │
│ ├── gef
│ │ ├── site.yml
│ │
└── roles
├── common
│ ├── download
│ │
│ ├── dynamic_groups
│ │
│ ├── post-audit
│ │
│ ├── pre-audit
│ │
│ ├── pre-check
│ │
│ ├── template-role
│ │
│ └── upgrade-completed
│
├── def
│ ├── backup
│ │
│ ├── install-application
│ │
│ ├── install-utility
│ │
│ ├── post-install
│ │
│ ├── pre-backup
│ │
│ ├── pre-install
│ │
│ └── validation
│
├── abc
│ ├── download
│ │
│ ├── install-application
│ │
│ ├── install-utility
│ │
│ ├── post-install
│ │
│ ├── post-validation
│ │
│ ├── pre-check
│ │
│ └── validation
│
└── gef
├── backup
│
├── install-application
│
├── install-utility
│
├── post-install
│
├── pre-backup
│
├── pre-install
我执行剧本时得到
"fatal: [localhost]: FAILED! => {"reason": "Unable to retrieve file contents\nCould not find or access '/tmp/playbook/Test/playbooks/dsc/playbooks/common-stages-tasks/sub_job_id_creation.yml'"}"
注意:工作目录为(/ tmp / playbook / Test),我正在执行以下命令:
/tmp/playbook/Test# ansible-playbook -i environments/preprod playbooks/abc/site.yml
所以我只想知道我将所有常见任务放在哪里,以及如何为常见任务定义变量,以便我可以在所有角色中使用这些任务?
在这种情况下最佳的目录结构是什么?