现在我有两个我执行的剧本。一个用于code_update,另一个用于整个站点更新。我想要一个“快速代码更新”,它不会运行任何NPM任务。
目前任务看起来如下:
---
- name: Create app database
mysql_db: name={{ app_db_name }} state=present
- name: Copy deploy key
copy:
src: templates/path.pem
dest: "{{ ssh_key_path }}"
owner: "{{ app_user }}"
mode: 0600
- name: Create app dir
file:
path: "{{ app_dir }}"
state: directory
mode: 0755
owner: "{{ app_user }}"
- name: Create log dir
file:
path: "{{ log_dir }}"
state: directory
recurse: yes
mode: 0755
owner: "{{ app_user }}"
- name: Pull sixnexus app
git:
repo: "{{ app_repo }}"
dest: "{{ app_dir }}"
version: master
force: yes
accept_hostkey: yes
ssh_opts: "-i {{ ssh_key_path }}"
- name: Create venv
pip:
virtualenv: "{{ app_env }}"
requirements: "{{ app_dir }}/requirements.txt"
- name: Copy local_settings.py
template:
src: templates/local_settings.py.j2
dest: "{{ app_dir }}/local_settings.py"
owner: "{{ app_user }}"
mode: 0755
- name: Run migrations
django_manage:
command: migrate
app_path: "{{ app_dir }}"
virtualenv: "{{ app_env }}"
# Partially doing this to save on memory
- name: Stop Elasticsearch
service: name=elasticsearch state=stopped
- name: Install react deps
command: npm install chdir=/home/ubuntu/path/app/react_ui
- name: Package react app
command: npm run package chdir=/home/ubuntu/path/app/react_ui
- name: Start Elasticsearch
service: name=elasticsearch state=started
- name: Run collectstatic
django_manage:
command: collectstatic
app_path: "{{ app_dir }}"
virtualenv: "{{ app_env }}"
我想编辑这个游戏看起来像这样:
---
- name: Create app database
mysql_db: name={{ app_db_name }} state=present
- name: Copy deploy key
copy:
src: templates/sixnexus_deploy_key.pem
dest: "{{ ssh_key_path }}"
owner: "{{ app_user }}"
mode: 0600
- name: Create app dir
file:
path: "{{ app_dir }}"
state: directory
mode: 0755
owner: "{{ app_user }}"
- name: Create log dir
file:
path: "{{ log_dir }}"
state: directory
recurse: yes
mode: 0755
owner: "{{ app_user }}"
- name: Pull sixnexus app
git:
repo: "{{ app_repo }}"
dest: "{{ app_dir }}"
version: master
force: yes
accept_hostkey: yes
ssh_opts: "-i {{ ssh_key_path }}"
- name: Create venv
pip:
virtualenv: "{{ app_env }}"
requirements: "{{ app_dir }}/requirements.txt"
- name: Copy local_settings.py
template:
src: templates/local_settings.py.j2
dest: "{{ app_dir }}/local_settings.py"
owner: "{{ app_user }}"
mode: 0755
- name: Run migrations
django_manage:
command: migrate
app_path: "{{ app_dir }}"
virtualenv: "{{ app_env }}"
# Partially doing this to save on memory
- name: Stop Elasticsearch
service: name=elasticsearch state=stopped
3
- name: Start Elasticsearch
service: name=elasticsearch state=started
- name: Run collectstatic
django_manage:
command: collectstatic
app_path: "{{ app_dir }}"
virtualenv: "{{ app_env }}"
但是,我无法想出如何为我的任务合并第二个文件。
您必须标记相关任务:
- name: Install react deps
command: npm install chdir=/home/ubuntu/path/app/react_ui
tags:
- npm
- name: Package react app
command: npm run package chdir=/home/ubuntu/path/app/react_ui
tags:
- npm
当你打电话给你的剧本时,你必须指定--skip-tags
选项:
$ ansible-playbook main.yml --skip-tags "npm"