
かなり遅い rsync 操作を含む、Web サイトのグループを 1 つのインフラストラクチャから別のインフラストラクチャに移行しています。移行プロセスには、ソース システムとターゲット システムの両方への変更が含まれます。
プロセスの一部である rsync 操作はかなり遅いため、各 Web サイトの詳細を含む var ファイルをループし、一度に 1 つの Web サイトを移動するために必要なタスクを実行します。
一部のタスクをソース システムで、一部のタスクをターゲット システムでターゲットにする方法が見つかりません。各タスクに hosts: を追加してこれを実行しようとしました: (すべてのタスクは単一のロールにあります)
私のプレイブック:
---
- hosts:
- tag_aws_autoscaling_groupName_thename
- tag_Name_server_name
vars_files:
- group_vars/all
roles:
- unmigratesite
移行サイトの役割:
---
- include_tasks: "unmigrateonesite.yml"
loop: "{{ wordpress_websites }}"
unmigrateonesite.yml:
- name: rsync site
hosts: tag_aws_autoscaling_groupName_thename
shell: rsync -avz /efs/www/{{new_folder}}/htdocs/ 172.31.18.217:/www/{{item.folder}}
run_once: true
register: rsync_out
- name: setup proxy host file
template: src=proxy-host.j2 dest=/efs/nginx/sites-available/{{item.name}} owner=root group=root mode=0644
hosts: tag_aws_autoscaling_groupName_thename
notify:
- restart nginx
tags:
- site
- nginx-host-conf
- nginx-temp-proxy
- name: setup wp-config.php WP_CONTENT_DIR on old server
lineinfile: name=/www/{{ folder }}/{{ configuration_file }} regexp=WP_CONTENT_DIR line="define('WP_CONTENT_DIR', '/www/{{folder}}/app');"
hosts: tag_Name_server_name
ignore_errors: yes
tags:
- wp-config.php
- wordpress
- site
- WP_CONTENT_DIR
しかし、エラーが発生します:
fatal: [54.219.216.237]: FAILED! => {"reason": "conflicting action statements: shell, hosts\n\nThe error appears to be in '/Users/jd/projects/bizinconline/ansible/roles/unmigratesite/tasks/unmigrateonesite.yml': line 22, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: rsync site\n ^ here\n"}
fatal: [54.193.100.223]: FAILED! => {"reason": "conflicting action statements: shell, hosts\n\nThe error appears to be in '/Users/jd/projects/bizinconline/ansible/roles/unmigratesite/tasks/unmigrateonesite.yml': line 22, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: rsync site\n ^ here\n"}
fatal: [13.57.52.221]: FAILED! => {"reason": "conflicting action statements: shell, hosts\n\nThe error appears to be in '/Users/jd/projects/bizinconline/ansible/roles/unmigratesite/tasks/unmigrateonesite.yml': line 22, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: rsync site\n ^ here\n"}
正確には 3 回 - ホストの数と同じ回数です。
一部のタスクを 1 つのサーバー グループに対して実行し、他のタスクを別のサーバー グループに対して実行するにはどうすればよいですか?
答え1
一部のタスクをソース システムで、一部のタスクをターゲット システムでターゲットにする方法が見つかりません。各タスクに hosts: を追加してこれを実行しようとしました: (すべてのタスクは単一のロールにあります)
これを読んで私が最初に思いついたのはhosts:
、when: "'old_server' in group_names"
when: "'new_server' in group_names"
もしそれがうまくいかなかったら、私は試してみるつもりdelegate_to
です。委任文書
一度に1つのウェブサイト
本当にゆっくりにしたい場合は、 の使用を検討してくださいserial: 1
。または--step
、クライ。
答え2
タスクをグループ化することで、異なるホストでタスクを実行します。演劇、それぞれがタスクが実行されるホストのセットを定義できます。個々のタスクにホストを設定することは実際には有効ではなく、これがエラー メッセージの直接の原因です。
次に示すのは、それぞれ異なるホストのセットを定義する 2 つのプレイの例です。各プレイは、そのタスクが実行されるホストを定義します。
- name: configure new hosts
hosts: tag_aws_autoscaling_groupName_thename
strategy: free
tasks:
- name: rsync site
shell: rsync -avz /efs/www/{{new_folder}}/htdocs/ 172.31.18.217:/www/{{item.folder}}
run_once: true
register: rsync_out
- name: setup proxy host file
template: src=proxy-host.j2 dest=/efs/nginx/sites-available/{{item.name}} owner=root group=root mode=0644
notify:
- restart nginx
tags:
- site
- nginx-host-conf
- nginx-temp-proxy
上記は 2 つのタスクを含む 1 つのプレイです。下記は 1 つのタスクを含む 1 つのプレイです。
- name: configure old hosts
hosts: tag_Name_server_name
strategy: free
tasks:
- name: setup wp-config.php WP_CONTENT_DIR on old server
lineinfile: name=/www/{{ folder }}/{{ configuration_file }} regexp=WP_CONTENT_DIR line="define('WP_CONTENT_DIR', '/www/{{folder}}/app');"
ignore_errors: yes
tags:
- wp-config.php
- wordpress
- site
- WP_CONTENT_DIR