2017年2月18日 星期六

使用 Register 自定二個變數,要在同一個 task 裡去執行

OS Environment

CentOS Linux release 7.3.1611 (Core)

Ansible Version

ansible 2.2.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides

task.yml

- name: Get Blob Name Path
  shell: az storage blob list -o table -c {{ BLOB_CONTAINER }} --account-name {{ backup_account }} --account-key {{ backup_key }} |  grep -Eo '{{restorebuildnumber.content}}.tar.gz|{{ restorebuildnumber.content }}/*/.*.gz'
  register: blobname

- name: Get Tar File Name
  shell: az storage blob list -o table -c {{ BLOB_CONTAINER }} --account-name {{ backup_account }} --account-key {{ backup_key }} |  grep -Eo '{{restorebuildnumber.content}}.tar.gz|{{ restorebuildnumber.content }}/*/.*.gz' | cut -d'/' -f3
  register: tarfilename

- name: Download {{ restorebuildnumber.content }}.tar.gz
  shell: az storage blob download -c {{ BLOB_CONTAINER }} -n {{ item.0 }} -f /tmp/{{restorebuildnumber.content}}/{{ item.1 }} --account-name {{ backup_account }} --account-key {{ backup_key }}
  with_together:
    -  "{{ blobname.stdout_lines }}"
    -  "{{ tarfilename.stdout_lines }}"
這個的重點是用 with_together 就可以達成目的了
Reference:

使用『差集』來排除不需要的檔案

OS Environment

CentOS Linux release 7.3.1611 (Core)

Ansible Version

ansible 2.2.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides

使用情境說明

先去抓所有的tar檔後,註冊一個變數AllTarFileName,再echo需要排除的檔名,並且也把它註冊成一個變數TarName,之後就可以在解tar檔時,使用差集的方式,將不需要的檔案做排除。

task.yml

- name: Get All Tar Files Name
  shell: az storage blob list -o table -c {{ BLOB_CONTAINER }} --account-name {{ BACKUP_ACCOUNT }} --account-key {{ BACKUP_KEY }} |  grep -Eo '{{RestoreBuildNumber.content}}.tar.gz|{{ RestoreBuildNumber.content }}/*/.*.gz' | cut -d'/' -f3
  register: AllTarFileName

- name: Get {{RestoreBuildNumber.content}}.tar.gz Name
  shell: echo '{{ RestoreBuildNumber.content }}.tar.gz'
  register: TarName

- name: Unarchive {{RestoreBuildNumber.content}}.tar.gz To /tmp/{{RestoreBuildNumber.content}}/data/
  shell: tar -zxvf /tmp/{{RestoreBuildNumber.content}}/{{item}} -C /tmp/{{RestoreBuildNumber.content}}/data/
  with_items:
    - "{{TarName.stdout_lines }}"

- name: Unarchive All Archives Tar Files
  shell: tar -zxvf /tmp/{{RestoreBuildNumber.content}}/{{item}} -C /tmp/{{RestoreBuildNumber.content}}/backups/
  with_items:
    - "{{ AllTarFileName.stdout_lines | difference(TarName.stdout_lines) }}"
Reference:
感謝 Ansible Taiwan - Jim T. Tang 大大的建議。

2017年2月7日 星期二

uwsgi unix domain socket error

uwsgi unix domain socket error

Nginx Error Message

2017/02/08 14:33:15 [crit] 31592#31592: *1 connect() to unix:///tmp/service.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.1.10, server: beta-hello.com, request: "GET /traffic_funnel HTTP/1.1", upstream: "uwsgi://unix:///tmp/service.sock:", host: "beta-hello.com"

解決辦法

原本都是把socket放在 /tmp 下,但好像每個服務看到的 /tmp 是不一樣的,所以還放在 /var/run 或是放在 /run 底下才會正常

原文

You can't place sockets intended for interprocess communication in /tmp.
For security reasons, recent versions of Fedora use namespaced temporary directories, meaning every service sees a completely different /tmp and can only see its own files in that directory.
To resolve the issue, place the socket in a different directory, such as /run (formerly known as /var/run).

Reference