为什么我的剧本没有调用角色?

Why is my playbook not calling up the roles?

我有一个从我的 Vagrantfile 调用的 ansible 剧本:

config.vm.provision "ansible" do |ansible|
     ansible.playbook = "provision/playbook.yml"
     ansible.sudo = true
     ansible.verbose = "vvvv"
     ansible.limit = "all"
     # ansible.inventory_path = "provision/hosts"
end

这是剧本:

---
- hosts: all
  roles:
    - common

我的目录结构是:

.
├── provision
│   ├── hosts
│   ├── playbook.yml
│   └── roles
│       └── common
│           ├── install_conda.yml
│           └── reqs.yml
├── ubuntu-xenial-16.04-cloudimg-console.log
└── Vagrantfile

我的问题是当我 运行 vagrant up 它不 运行 install_conda.yml 和 reqs.yml

相关输出:

ansible/.vagrant/provisioners/ansible/inventory --sudo -vvvv provision/playbook.yml
Using /home/lowks/.ansible.cfg as config file
Loaded callback default of type stdout, v2.0
1 plays in provision/playbook.yml
PLAY ***************************************************************************
TASK [setup] *******************************************************************
<127.0.0.1> ESTABLISH SSH CONNECTION FOR USER: ubuntu
<127.0.0.1> SSH: EXEC ssh -C -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=2222 -o 'IdentityFile="/home/lowks/Projects/personal/ansible/.vagrant/machines/default/virtualbox/private_key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=30 -o ControlPath=/home/lowks/.ansible/cp/ansible-ssh-%h-%p-%r -tt 127.0.0.1 '( umask 22 && mkdir -p "$( echo $HOME/.ansible/tmp/ansible-tmp-1465289160.96-19604199657213 )" && echo "$( echo $HOME/.ansible/tmp/ansible-tmp-1465289160.96-19604199657213 )" )'
<127.0.0.1> PUT /tmp/lowks/tmpzSsrdn TO /home/ubuntu/.ansible/tmp/ansible-tmp-1465289160.96-19604199657213/setup
<127.0.0.1> SSH: EXEC sftp -b - -C -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=2222 -o 'IdentityFile="/home/lowks/Projects/personal/ansible/.vagrant/machines/default/virtualbox/private_key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=30 -o ControlPath=/home/lowks/.ansible/cp/ansible-ssh-%h-%p-%r '[127.0.0.1]'
<127.0.0.1> ESTABLISH SSH CONNECTION FOR USER: ubuntu
<127.0.0.1> SSH: EXEC ssh -C -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=2222 -o 'IdentityFile="/home/lowks/Projects/personal/ansible/.vagrant/machines/default/virtualbox/private_key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=30 -o ControlPath=/home/lowks/.ansible/cp/ansible-ssh-%h-%p-%r -tt 127.0.0.1 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-xokgppdafgvlsnbystytwqbmniidqhhq; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1465289160.96-19604199657213/setup; rm -rf "/home/ubuntu/.ansible/tmp/ansible-tmp-1465289160.96-19604199657213/" > /dev/null 2>&1'"'"'"'"'"'"'"'"''"'"''
ok: [default]

PLAY RECAP *********************************************************************
default                    : ok=1    changed=0    unreachable=0    failed=0  

install_conda.yml

---
# necessary steps to deploy the role.
- hosts: all

- name: check if already installed
  stat: path=/opt/miniconda2/bin/conda
  register: bin_conda
  changed_when: bin_conda.stat.exists == False

- name: download miniconda installer
  # sudo: no
  get_url:
    url=https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh
    dest=/tmp/miniconda.sh
    mode=0755
  register: miniconda_downloaded
  when: bin_conda.stat.exists == False

- name: install miniconda
  # sudo: no
  shell: "/tmp/miniconda.sh -b -p /opt/miniconda2 creates=/opt/miniconda2 executable=/bin/bash"
  register: miniconda_installed
  when: miniconda_downloaded | success
  notify:
    - remove miniconda setup script
    - update conda to latest version

我在这里错过了什么?

Ansible 在您的 roles/common/tasks.

中查找 main.yml 文件

只需将其添加到您的文件夹即可

.
├── provision
│   ├── hosts
│   ├── playbook.yml
│   └── roles
│       └── common
│           └── tasks        
│               ├── main.yml
│               ├── install_conda.yml
│               └── reqs.yml
├── ubuntu-xenial-16.04-cloudimg-console.log
└── Vagrantfile    

并包括其他角色:

---

- include: install_conda.yml
- include: reqs.yml