Ansible - msg:没有包裹匹配' $ item'是可用的

时间:2015-05-06 05:48:21

标签: ansible ansible-playbook

我需要设置我的服务器。我是以下的ansible剧本。

---

- hosts: webservers
  user: root
  sudo: yes
  tasks:
    - name: add nginx ppa
      action: apt_repository repo=ppa:nginx/stable state=present

    - name: install common packages needed for python application development
      action: apt pkg=$item state=installed
      with_items:
        - libpq-dev
        - libmysqlclient-dev
        - libxml2-dev
        - libxslt1-dev
        - mysql-client
        - python-dev
        - python-setuptools
        - python-mysqldb
        - build-essential
        - git
        - nginx

    - name: install pip
      action: easy_install name=pip

    - name: install various libraries with pip
      action: pip name=$item state=present
      with_items:
        - uwsgi

  handlers:
    - name: restart nginx
      service: name=nginx state=restarted

当我运行此脚本时,以下是输出

PLAY [webservers] ************************************************************* 

GATHERING FACTS *************************************************************** 
ok: [IP]

TASK: [add nginx ppa] ********************************************************* 
ok: [IP]

TASK: [install common packages needed for python application development] ***** 
failed: [IP] => (item=libpq-dev,libmysqlclient-dev,libxml2-dev,libxslt1-dev,mysql-client,python-dev,python-setuptools,python-mysqldb,build-essential,git,nginx) => {"failed": true, "item": "libpq-dev,libmysqlclient-dev,libxml2-dev,libxslt1-dev,mysql-client,python-dev,python-setuptools,python-mysqldb,build-essential,git,nginx"}
msg: No package matching '$item' is available

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/praful/setup_server.yaml.retry

IP              : ok=2    changed=0    unreachable=0    failed=1   

我已将this链接称为相同的链接。

我是ansible的新手并且不理解错误,因为with_items中提供的包名中没有拼写错误。 错误究竟是什么?

1 个答案:

答案 0 :(得分:10)

您需要jinja变量语法package org.student.registration.dao; import java.io.IOException; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import org.apache.log4j.Logger; import org.json.JSONException; import org.student.jdbc.util.JDBCConnectionUtil; import org.student.registration.to.StudentContactDetailsTO; import org.student.registration.to.StudentDetailsTO; import org.student.registration.to.StudentPreviousEducationDetailsTO; /** * @author cerdik */ public class AllStudentsDetailsListDAO { private static final Logger LOGGER = Logger.getLogger(AllStudentsDetailsListDAO.class); /** * @accessSpecifier public * @returnType JSONArray * @return studentDetails * @throws ClassNotFoundException * @throws SQLException * @throws IOException * @throws JSONException */ public List<StudentDetailsTO> getAllStudentsDelailsList() throws ClassNotFoundException, SQLException, IOException, JSONException{ try{ LOGGER.info("getAllStudentsDelailsList Method started"); int studentId=0; String retrieveQuery="SELECT " + "student_details_t.student_id," + "student_details_t.stream_type_id," + "student_details_t.first_name," + "student_details_t.last_name," + "student_details_t.address," + "student_details_t.gender," + "student_details_t.phone_no," + "student_contact_details_t.student_contact_details_id," + "student_contact_details_t.contact_relation_type_id," + "student_contact_details_t.name," + "student_contact_details_t.address," + "student_contact_details_t.phone_no," + "student_previous_education_details_t.previous_education_details_id," + "student_previous_education_details_t.education_type_id," + "student_previous_education_details_t.institution_of_study," + "student_previous_education_details_t.year_of_passing," + "student_previous_education_details_t.major_paper," + "student_previous_education_details_t.percentage," + "student_previous_education_details_t.board_of_study," + "stream_types_t.stream_type_name," + "education_types_t.education_type_name," + "contact_relation_type_t.contact_relation_type_name " + "FROM " + "(student_details_t INNER JOIN student_contact_details_t ON student_details_t.student_id=student_contact_details_t.student_id " + "INNER JOIN contact_relation_type_t ON student_contact_details_t.contact_relation_type_id=contact_relation_type_t.contact_relation_type_id " + "INNER JOIN student_previous_education_details_t ON student_details_t.student_id=student_previous_education_details_t.student_id " + "INNER JOIN education_types_t ON education_types_t.education_type_id=student_previous_education_details_t.education_type_id " + "INNER JOIN stream_types_t ON stream_types_t.stream_type_id=student_details_t. stream_type_id) " + "ORDER BY student_details_t.student_id"; PreparedStatement prepareStatement=JDBCConnectionUtil.getConnection().prepareStatement(retrieveQuery); ResultSet resultSet=prepareStatement.executeQuery(); LOGGER.info("getAllStudentsDelailsList Query is Excuted"); List<StudentDetailsTO> allStudents=new ArrayList<StudentDetailsTO>(); StudentDetailsTO studentsDetails=null; HashSet<StudentPreviousEducationDetailsTO>previousEducationDetail=null;//new HashSet<StudentPreviousEducationDetailsTO>(); HashSet<StudentContactDetailsTO>contactDetail=null;//new HashSet<StudentContactDetailsTO>(); while(resultSet.next()){ if(studentsDetails==null){ studentsDetails=new StudentDetailsTO(); studentsDetails.setStudentId(resultSet.getInt("student_id")); studentsDetails.setStudentStreamId(resultSet.getInt("stream_type_id")); studentsDetails.setStreamName(resultSet.getString("stream_type_name")); studentsDetails.setFirstName(resultSet.getString("first_name")); studentsDetails.setLastName(resultSet.getString("last_name")); studentsDetails.setAddress(resultSet.getString("address")); studentsDetails.setGender(resultSet.getString("gender")); studentsDetails.setPhoneNo(resultSet.getString("phone_no")); contactDetail=new HashSet<StudentContactDetailsTO>(); StudentContactDetailsTO studentContactDetail=new StudentContactDetailsTO(); studentContactDetail.setStudentId(resultSet.getInt("student_id")); studentContactDetail.setStudentContactDetailsId(resultSet.getInt("student_contact_details_id")); studentContactDetail.setContactTypeName(resultSet.getString("contact_relation_type_name")); studentContactDetail.setContactRelationTypeId(resultSet.getInt("contact_relation_type_id")); studentContactDetail.setName(resultSet.getString(10)); studentContactDetail.setAddress(resultSet.getString(11)); studentContactDetail.setPhoneNo(resultSet.getString(12)); contactDetail.add(studentContactDetail); studentsDetails.setStudentContactDetails(contactDetail); previousEducationDetail=new HashSet<StudentPreviousEducationDetailsTO>(); StudentPreviousEducationDetailsTO previousEducationDetails=new StudentPreviousEducationDetailsTO(); previousEducationDetails.setStudentId(resultSet.getInt("student_id")); previousEducationDetails.setEducationTypeId(resultSet.getInt("education_type_id")); previousEducationDetails.setPreviousEducationDetailsId(resultSet.getInt("previous_education_details_id")); previousEducationDetails.setPreviousEducationTypeName(resultSet.getString("education_type_name")); previousEducationDetails.setInstitutionName(resultSet.getString("institution_of_study")); previousEducationDetails.setMajorSubject(resultSet.getString("major_paper")); previousEducationDetails.setPercentage(resultSet.getString("percentage")); previousEducationDetails.setBoardOfStudy(resultSet.getString("board_of_study")); previousEducationDetails.setYearOfPassing(resultSet.getString("year_of_passing")); previousEducationDetail.add(previousEducationDetails); studentsDetails.setStudentPreviousEducationDetails(previousEducationDetail); }else{ if(resultSet.getInt("student_id")!=studentsDetails.getStudentId()){ allStudents.add(studentsDetails); studentsDetails=new StudentDetailsTO(); studentsDetails.setStudentId(resultSet.getInt("student_id")); studentsDetails.setStudentStreamId(resultSet.getInt("stream_type_id")); studentsDetails.setStreamName(resultSet.getString("stream_type_name")); studentsDetails.setFirstName(resultSet.getString("first_name")); studentsDetails.setLastName(resultSet.getString("last_name")); studentsDetails.setAddress(resultSet.getString("address")); studentsDetails.setGender(resultSet.getString("gender")); studentsDetails.setPhoneNo(resultSet.getString("phone_no")); contactDetail=new HashSet<StudentContactDetailsTO>(); StudentContactDetailsTO studentContactDetail=new StudentContactDetailsTO(); studentContactDetail.setStudentId(resultSet.getInt("student_id")); studentContactDetail.setStudentContactDetailsId(resultSet.getInt("student_contact_details_id")); studentContactDetail.setContactTypeName(resultSet.getString("contact_relation_type_name")); studentContactDetail.setContactRelationTypeId(resultSet.getInt("contact_relation_type_id")); studentContactDetail.setName(resultSet.getString(10)); studentContactDetail.setAddress(resultSet.getString(11)); studentContactDetail.setPhoneNo(resultSet.getString(12)); contactDetail.add(studentContactDetail); studentsDetails.setStudentContactDetails(contactDetail); previousEducationDetail=new HashSet<StudentPreviousEducationDetailsTO>(); StudentPreviousEducationDetailsTO previousEducationDetails=new StudentPreviousEducationDetailsTO(); previousEducationDetails.setStudentId(resultSet.getInt("student_id")); previousEducationDetails.setEducationTypeId(resultSet.getInt("education_type_id")); previousEducationDetails.setPreviousEducationDetailsId(resultSet.getInt("previous_education_details_id")); previousEducationDetails.setPreviousEducationTypeName(resultSet.getString("education_type_name")); previousEducationDetails.setInstitutionName(resultSet.getString("institution_of_study")); previousEducationDetails.setMajorSubject(resultSet.getString("major_paper")); previousEducationDetails.setPercentage(resultSet.getString("percentage")); previousEducationDetails.setBoardOfStudy(resultSet.getString("board_of_study")); previousEducationDetails.setYearOfPassing(resultSet.getString("year_of_passing")); previousEducationDetail.add(previousEducationDetails); studentsDetails.setStudentPreviousEducationDetails(previousEducationDetail); }else{ StudentPreviousEducationDetailsTO previousEducationDetails=new StudentPreviousEducationDetailsTO(); previousEducationDetails.setStudentId(resultSet.getInt("student_id")); previousEducationDetails.setEducationTypeId(resultSet.getInt("education_type_id")); enter code here previousEducationDetails.setPreviousEducationDetailsId(resultSet.getInt("p revious_education_details_id")); previousEducationDetails.setPreviousEducationTypeName(resultSet.getString( "education_type_name")); previousEducationDetails.setInstitutionName(resultSet.getString("instituti on_of_study")); previousEducationDetails.setMajorSubject(resultSet.getString("major_paper" )); previousEducationDetails.setPercentage(resultSet.getString("percentage")); previousEducationDetails.setBoardOfStudy(resultSet.getString("board_of_stu dy")); previousEducationDetails.setYearOfPassing(resultSet.getString("year_of_pas sing")); previousEducationDetail.add(previousEducationDetails); studentsDetails.setStudentPreviousEducationDetails(previousEducationDetail ); } StudentContactDetailsTO studentContactDetail=new StudentContactDetailsTO(); studentContactDetail.setStudentId(resultSet.getInt("student_id")); studentContactDetail.setStudentContactDetailsId(resultSet.getInt("student_ contact_details_id")); studentContactDetail.setContactTypeName(resultSet.getString("contact_relat ion_type_name")); studentContactDetail.setContactRelationTypeId(resultSet.getInt("contact_re lation_type_id")); studentContactDetail.setName(resultSet.getString(10)); studentContactDetail.setAddress(resultSet.getString(11)); studentContactDetail.setPhoneNo(resultSet.getString(12)); contactDetail.add(studentContactDetail); studentsDetails.setStudentContactDetails(contactDetail); } } allStudents.add(studentsDetails);//To add last student object into the list LOGGER.info("Student Details retrieved by studentId and supply to handler successfully "); return allStudents; }catch(ClassNotFoundException e){ LOGGER.error("ERROR OCCURED : ClassNotFoundException getAllStudentsDelailsList Method"); throw e; }catch(SQLException e){ LOGGER.error("ERROR OCCURED : SQLException getAllStudentsDelailsList Method"); throw e; }catch(IOException e){ LOGGER.error("ERROR OCCURED : IOException getAllStudentsDelailsList Method"); throw e; }catch(Exception e){ LOGGER.error("ERROR OCCURED : Exception getAllStudentsDelailsList Method"); throw e; } } } ,其中{{item}}