我如何编写单一角色并随着脚本的进展连接到不同的主机?
这是我想要做的一个例子,但我收到了如下所示的错误。
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to be in '/etc/ansible/roles/customer_setups/microlight/customer_app_template/tasks/main.yml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
# tasks file for /etc/ansible/roles/customer_app_template
- hosts: synbill-apps
^ here
---
# tasks file for /etc/ansible/roles/customer_app_template
- hosts: synbill-apps
tasks:
- name: Clone syndicatebilling repository into a new customer app
git:
repo: [email protected]:xxxx/xxx.git
version: syndicateBookings
dest: /var/www/html/microlight
force: yes
- name: run npm install
npm:
path: /var/www/html/microlight
- name: copy .env file
copy:
src: files/.env
dest: /var/www/html/microlight/.env
- name: create new app key
command: chdir=/var/www/html/microlight adonis key:generate
- name: migrate database
command: chdir=/var/www/html/microlight adonis migration:run --force
- name: start the app
command: chdir=/var/www/html/microlight pm2 start server.js --name placeholder_domain
- name: save the pm2 config
command: chdir=/var/www/html/microlight pm2 save
- hosts: synbill-db
- name: "Install Mysql Client package"
apt:
name: "{{ item }}"
state: present
with_items:
- mysql-client
- python3-dev
- libmysqlclient-dev
- python3-mysqldb
- name: Create syndicate database
mysql_db:
name: microlight
state: present
login_user: simon
login_password: xxxxxxxxxxx
- hosts: synbill-apps
.....now the db is setup do some more work on the apps server
- hosts: synbill-webserver
.... now setup the virtual host
- hosts: synbill-db
.... now update the database to so user knows everything is setup.
答案1
文件中的任务tasks.yml
看起来不太适合角色抽象。我只想写一个剧本。
为了能够执行剧本,您需要在此处添加“任务部分”:
- hosts: synbill-db
tasks:
- name: "Install Mysql Client package"
我认为用角色抽象代码的最简单的方法是编写两个角色,一个用于应用程序,一个用于数据库。