2016-12-06 10 views
0

Apacheをインストールし、設定ファイルをコピーしてから起動し、実行するように設定する必要があります。私は空白や再配置をいじって試してみました危険なプレイブック - Apacheのインストール/設定エラー

error: ERROR! Syntax Error while loading YAML. 
The error appears to have been in '/etc/ansible/playbook.yml': line 3, column 1, but may 
be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 

- hosts: example 
tasks: 
^ here 

ansible-playbook playbook.yml、私はこれを受け取る:私は、コマンドを実行すると、しかし

--- 
- hosts: example 

tasks: 
- name:Install Apache 
    command: yum install --quiet -y httpd httpd-devel 
- name:Copy configuration files 
    command:> 
    cp httpd.conf /etc/httpd/conf/httpd.conf 
- command:> 
    cp httpd-vshosts.conf /etc/httpd/conf/httpd-vshosts.conf 
- name:Start Apache and configure it to run 
    command: service httpd start 
- command: chkconfig httpd on 

:ここ

は、これまでに書かれた脚本であります私はまだこのエラーを受け取ります。私はそれが私がここで欠けている小さなものだと確信していますが、それは終わりに私を悩ませている!どんな助けもありがとう!本当にありがとう。

答えて

2

エラーメッセージに関して、インデントに注意する必要があります。

--- 
- hosts: example 

    tasks: 
    - name: Install Apache 
     command: yum install --quiet -y httpd httpd-devel 
    - name: Copy configuration files 
     command: cp httpd.conf /etc/httpd/conf/httpd.conf 
    - command: cp httpd-vshosts.conf /etc/httpd/conf/httpd-vshosts.conf 
    - name: Start Apache and configure it to run 
     command: service httpd start 
    - command: chkconfig httpd on 

しかし、これはむしろ Ansibleを使用しない方法の例です:これは、のようになります方法です。

私はあなただけAnsibleを使用し始め、物事を確認したいのですが、代わりにcommandモジュールですべてを実行するので、あなたはむしろyumまたはserviceのように、ネイティブモジュールを活用する必要があると仮定します。リンクされたドキュメントページの例を見てください。


また、一部のタスクには名前がありません。例えば、これらは、二つの異なるタスク(名前の最初の1秒1なし)です:

- name: Copy configuration files 
    command: cp httpd.conf /etc/httpd/conf/httpd.conf 
- command: cp httpd-vshosts.conf /etc/httpd/conf/httpd-vshosts.conf 

もっと適切な命名は次のようになります。

- name: Copy one configuration file 
    command: cp httpd.conf /etc/httpd/conf/httpd.conf 
- name: Copy another configuration file 
    command: cp httpd-vshosts.conf /etc/httpd/conf/httpd-vshosts.conf 

もう一つの問題:このコマンドは意志ターゲットマシン上の現在のディレクトリにhttpd-vshosts.confがないはずであるため、失敗します。

- command: cp httpd-vshosts.conf /etc/httpd/conf/httpd-vshosts.conf 

完全パスを指定する必要があります。

+0

ありがとうございます。それは私のために働いた..問題は空白であった! –

関連する問題