Ansible变量未正确注入,'[u'由ansible添加

时间:2018-08-16 10:26:57

标签: ansible

我写了一个任务,在本地克隆git repo。当对repo url进行了硬编码时,它很好用,但是当我使用变量时,我得到了not found

任务在这里

#roles/clone/tasks/mail.yml
---
- name: current_working_directory
  local_action: shell pwd
  register: current_working_directory

- name: check out a git repository
  local_action: git repo=https://username@bitbucket.org/project/repo.git dest="{{current_working_directory.stdout}}/roles/{{deployer_role}}/files/repo"

使用此剧本文件

- name:  deploy application code
  hosts: all
  remote_user: root
  vars:
    deployer_role:
      - angular
  roles:
    - clone
    - angular

但是当尝试在我的剧本文件中定义变量时,由于某种奇怪的字符an not found,我在此处添加了启动命令

/usr/bin/git clone --origin origin 'https:********@bitbucket.org/project/repo.git'\"'\"']' '/Users/jerome/Developpement/ansible/roles/[u'\"'\"'angular'\"'\"']/files/repo'

我已经完成了基本配置

任务在这里

#roles/clone/tasks/mail.yml
---
- name: current_working_directory
  local_action: shell pwd
  register: current_working_directory

- name: check out a git repository
  local_action: git repo=https://{{repository}} dest="{{current_working_directory.stdout}}/roles/{{deployer_role}}/files/repo"

使用此剧本文件

- name:  deploy application code
  hosts: all
  remote_user: root
  vars:
    deployer_role:
      - angular
    repository:
      - username@bitbucket.org/project/repo.git
  roles:
    - clone
    - angular

所有[u\"来自哪里?

1 个答案:

答案 0 :(得分:0)

{{deployer_role}}是一个列表,这就是为什么您有这样的角色,所以您必须遍历可以提供给角色的电位值,因此必须这样做

- name: check out a git repository
  local_action: git repo=https://username@bitbucket.org/project/repo.git dest="{{current_working_directory.stdout}}/roles/{{item}}/files/repo"
  with_items: "{{deployer_role}}"