【问题标题】:Problem with Ansible playbook quoted variableAnsible剧本引用变量的问题
【发布时间】:2019-01-10 12:37:18
【问题描述】:

我正在尝试运行以下 ansible 剧本。但是,我在运行它时遇到错误。

---
- hosts: live
  remote_user: root
  vars:
    destination: /var/www/html/app.mytest.com/releases/{{ ansible_date_time.year }}{{ ansible_date_time.month }}{{ ansible_date_time.day }}{{ ansible_date_time.hour }}{{ ansible_date_time.minute }}{{ ansible_date_time.second }}
  tasks:
  - git:
      repo: 'git@bitbucket:mytest/mytest.git'
      dest: "{{ destination }}"
      depth: 1
  - name: copying .env file to remote host
    copy:
      src: /root/playbooks/resources/live/.env
      dest: "{{ destination }}/"
  - name: php artisan migrate
      shell: "php {{ destination }}/artisan migrate"
  - name: php artisan package:discover
      shell: "php {{ destination }}/artisan package:discover"
  - name: npm install
      shell: "npm install"
  - name: npm run dev
      shell: "npm run dev"
  - name: php artisan queue:restart
      shell: "php {{ destination }}/artisan queue:restart"
  - name: service supervisord restart
      shell: "service supervisord restart"
  - name: php artisan queue:flush
      shell: "php {{ destination }}/artisan queue:flush"
...

我得到的错误如下:

希望能在解决此语法错误方面提供帮助。

【问题讨论】:

  • 尝试引用vars: destination: "/var/...." 的值。违规行通常高于错误消息中报告的行。

标签: ansible yaml


【解决方案1】:

任务的缩进是错误的。而不是

tasks:
- git:
    repo: 'git@bitbucket:mytest/mytest.git'
    dest: "{{ destination }}"

正确的语法是

tasks:
  - git:
      repo: 'git@bitbucket:mytest/mytest.git'
      dest: "{{ destination }}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2016-06-18
    • 1970-01-01
    • 2018-09-21
    相关资源
    最近更新 更多