Ansible,找不到角色错误

时间:2016-10-05 12:12:01

标签: configuration vagrant ansible ansible-playbook provisioning

我尝试播放以下针对localhost的playbook以提供Vagrant机器

ansible-playbook -i "localhost," -c local playbook.yml

我从github克隆了必要的角色,他们居住在相对路径==> default: ERROR! the role 'geerlingguy.java' was not found in /home/vagrant/provisioning/roles:/home/vagrant/provisioning:/etc/ansible/roles:/home/vagrant/provisioning/roles ==> default: ==> default: The error appears to have been in '/home/vagrant/provisioning/roles/jenkins/meta/main.yml': line 3, column 5, but may ==> default: be elsewhere in the file depending on the exact syntax problem. ==> default: ==> default: The offending line appears to be: ==> default: ==> default: dependencies: ==> default: - geerlingguy.java ==> default: ^ here

执行以下命令:roles/java输出此错误:

roles/geerlingguy/java

我从github克隆了缺失的依赖项,并尝试将其驻留在. ├── playbook.yml └── roles ├── base │   └── tasks │   └── main.yml ├── java │   ├── defaults │   │   └── main.yml │   ├── meta │   │   └── main.yml │   ├── README.md │   ├── tasks │   │   ├── main.yml │   │   ├── setup-Debian.yml │   │   ├── setup-FreeBSD.yml │   │   └── setup-RedHat.yml │   ├── templates │   │   └── java_home.sh.j2 │   ├── tests │   │   └── test.yml │   └── vars │   ├── Debian.yml │   ├── Fedora.yml │   ├── FreeBSD.yml │   ├── RedHat.yml │   ├── Ubuntu-12.04.yml │   ├── Ubuntu-14.04.yml │   └── Ubuntu-16.04.yml └── jenkins ├── defaults │   └── main.yml ├── handlers │   └── main.yml ├── meta │   └── main.yml ├── README.md ├── tasks │   ├── main.yml │   ├── plugins.yml │   ├── settings.yml │   ├── setup-Debian.yml │   └── setup-RedHat.yml ├── templates │   └── basic-security.groovy ├── tests │   ├── requirements.yml │   ├── test-http-port.yml │   ├── test-jenkins-version.yml │   ├── test-plugins-with-pinning.yml │   ├── test-plugins.yml │   ├── test-prefix.yml │   └── test.yml └── vars ├── Debian.yml └── RedHat.yml import android.app.ProgressDialog; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.util.JsonReader; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.HorizontalScrollView; import android.widget.TabHost; import android.widget.TableLayout; import android.widget.TableRow; import android.widget.TextView; import android.widget.Toast; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.BufferedInputStream; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; public class ClasesFragment extends Fragment { private static int NUM_PAGES = 13; private ViewPager mPager; private PagerAdapter mPagerAdapter; private ProgressDialog pDialog; private JsonReader reader; protected TableLayout MainLayoutDatos; protected View view; private TableRow[] datosTableRows; private String razon = ""; boolean success = false; private ArrayList<String> nombresEstaciones = new ArrayList<String>(); private ArrayList<ArrayList<Number>> aDatosVolList = new ArrayList<ArrayList<Number>>(); private ArrayList<ArrayList<Number>> aDatosNivelList = new ArrayList<ArrayList<Number>>(); private ArrayList<ArrayList<Number>> aFechasList = new ArrayList<ArrayList<Number>>(); public ProgressDialog pdLoading; public ClasesFragment() { // Required empty public constructor } static String convertStreamToString(java.io.InputStream is) { java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment view = inflater.inflate(R.layout.fragment_clases, container, false); TabHost tabhost = (TabHost) view.findViewById(R.id.tabHostClases); tabhost.setup(); TabHost.TabSpec spec1 = tabhost.newTabSpec("DATOS"); TabHost.TabSpec spec2 = tabhost.newTabSpec("GRÁFICOS"); spec1.setIndicator("DATOS"); spec1.setContent(R.id.pestanaDatosEmb); spec2.setIndicator("GRÁFICOS"); spec2.setContent(R.id.pestanaGrafEmb); tabhost.addTab(spec1); tabhost.addTab(spec2); HorizontalScrollView pestanaDatos = (HorizontalScrollView) view.findViewById(R.id.pestanaDatosEmb); //Create the layout para pestanaDatosEmb MainLayoutDatos = new TableLayout(view.getContext()); MainLayoutDatos.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT)); MainLayoutDatos.setStretchAllColumns(true); pestanaDatos.addView(MainLayoutDatos); NUM_PAGES = 5; mPager = (ViewPager) view.findViewById(R.id.pager); mPagerAdapter = new ScreenSlidePagerAdapter(getActivity().getSupportFragmentManager()); mPager.setAdapter(mPagerAdapter); pdLoading = new ProgressDialog(getActivity()); try { ConnectivityManager connMgr = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { new JsonTask().execute(new URL("http://www.myhost.com/android/clases")); } else { Toast.makeText(getActivity(), "Error de conexión", Toast.LENGTH_LONG).show(); } } catch (MalformedURLException e) { e.printStackTrace(); } return view; } public class JsonTask extends AsyncTask<URL, Void, String> { @Override protected String doInBackground(URL... urls) { String resultado = ""; HttpURLConnection con = null; try { // Establecer la conexión con = (HttpURLConnection) urls[0].openConnection(); con.setConnectTimeout(15000); con.setReadTimeout(10000); int statusCode = con.getResponseCode(); if (statusCode != 200) { System.out.println("ERROR ESTATUS CODE: " + String.valueOf(statusCode)); } else { // Parsear el flujo con formato JSON InputStream in = new BufferedInputStream(con.getInputStream()); resultado = convertStreamToString(in); } } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) { con.disconnect(); } } return resultado; } protected void onPreExecute() { pdLoading.setMessage("\tCargando información..."); pdLoading.show(); } @Override protected void onPostExecute(String resultado) { pdLoading.dismiss(); try { JSONObject respuesta = new JSONObject(resultado); JSONArray datos = respuesta.getJSONArray("datos"); for(int i=0;i<datos.length();i++){ JSONObject clase = datos.getJSONObject(i); TableRow row = new TableRow(view.getContext()); TextView text = new TextView(view.getContext()); text.setText(clase.getString("one")); text.setPadding(4,2,4,2); TextView text2 = new TextView(view.getContext()); text2.setText(clase.getString("two")); text2.setPadding(4,2,4,2); TextView text3 = new TextView(view.getContext()); text3.setText(clase.getString("three")); text3.setPadding(4,2,4,2); TextView text4 = new TextView(view.getContext()); text4.setText(clase.getString("four")); text4.setPadding(4,2,4,2); TextView text5 = new TextView(view.getContext()); text5.setText(clase.getString("five")); text5.setPadding(4,2,4,2); TextView text6 = new TextView(view.getContext()); text6.setText(clase.getString("six")); text6.setPadding(4,2,4,2); TextView text7 = new TextView(view.getContext()); text7.setText(clase.getString("seven")); text7.setPadding(4,2,4,2); TextView text8 = new TextView(view.getContext()); text8.setText(clase.getString("eight")); text8.setPadding(4,2,4,2); TextView text9 = new TextView(view.getContext()); text9.setText(clase.getString("nine")); text9.setPadding(4,2,4,2); TextView text0 = new TextView(view.getContext()); text0.setText(clase.getString("ten")); text0.setPadding(4,2,4,2); row.addView(text); row.addView(text2); row.addView(text3); row.addView(text4); row.addView(text5); row.addView(text6); row.addView(text7); row.addView(text8); row.addView(text9); row.addView(text0); MainLayoutDatos.addView(row); } } catch (JSONException e) { e.printStackTrace(); } } } private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { return ScreenSlidePageFragment.create(position); } @Override public int getCount() { return NUM_PAGES; } } } 的相对路径中,但要么没有解决问题,要么错误保持不变。< / p>

我希望将所有角色保存在同步配置文件夹中,而不使用ansible-galaxy运行时,以使配置方法尽可能自包含。

这是现在的配置文件夹结构

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="es.redhidrosurmedioambiente.saihredhidrosur.EmbalsesFragment"
    android:baselineAligned="false">


    <TabHost
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tabHostEmbalses"
        android:layout_gravity="center_horizontal">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:clickable="true"
                android:tabStripEnabled="true"></TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <HorizontalScrollView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/pestanaDatosEmb" />

                <ScrollView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/pestanaGrafEmb">

                    <android.support.v4.view.ViewPager
                        xmlns:android="http://schemas.android.com/apk/res/android"
                        android:id="@+id/pager"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" />

                </ScrollView>

            </FrameLayout>
        </LinearLayout>
    </TabHost>


</LinearLayout>

3 个答案:

答案 0 :(得分:2)

您应该在/roles文件夹(或系统文件夹)中安装或克隆所有所需角色

ansible-galaxy install -p ROLES_PATH geerlingguy.java

应该解决这个具体问题。

但是,best practice应该使用requirements.yml文件,您需要所有需要的角色,然后将ansible-galaxy直接安装在您的剧本中。

- name: run ansible galaxy
  local_action: command ansible-galaxy install -r requirements.yml --ignore-errors

答案 1 :(得分:1)

以下是解决方案:角色所需的路径为roles/geerlingguy.java/,而不是roles/geerlingguy/java/

答案 2 :(得分:1)

简单的符号链接就像一个没有任何安装的魅力:

$ mkdir /home/USER/ansible && ln -s /home/USER/GIT/ansible-root/roles