2015-12-21 99 views
1

我想連接到EC2實例,並在劇本運行任務運行在EC2上instanse ansible任務

playbook.yml:

--- 
- hosts: 'all' 
    remote_user: 'ubuntu' 

    vars: 
    ruby_version: '2.2.4' 
    user: 'deploy' 
    home: '/home/{{ user }}' 
    rbenv_root: '{{ home }}/.rbenv' 
    name: 'app' 
    application: '{{ home }}/applications/{{ name }}' 

    tasks: 
    - name: 'apt | install dependencies' 
     action: 'apt pkg={{ item }}' 
     with_items: 
     - 'build-essential' 
     - 'libssl-dev' 
     - 'libyaml-dev' 
     - 'libreadline6-dev' 
     - 'zlib1g-dev' 
     - 'libcurl4-openssl-dev' 
     - 'git' 
     - 'nginx' 
     - 'postgresql' 
     - 'postgresql-contrib' 
     - 'libpq-dev' 
     - 'imagemagick' 
     - 'libmagickwand-dev' 
     - 'htop' 

運行命令:

ansible-playbook -i11.111.1.111, playbook.yml 

,並得到這個:

PLAY [all] ******************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [11.111.1.111] 

TASK: [apt | install dependencies] ******************************************** 
failed: [11.111.1.111] => (item=build-essential,libssl-dev,libyaml-dev,libreadline6-dev,zlib1g-dev,libcurl4-openssl-dev,git,nginx,postgresql,postgresql-contrib,libpq-dev,imagemagick,libmagickwand-dev,htop) => {"failed": true, "item": "build-essential,libssl-dev,libyaml-dev,libreadline6-dev,zlib1g-dev,libcurl4-openssl-dev,git,nginx,postgresql,postgresql-contrib,libpq-dev,imagemagick,libmagickwand-dev,htop"} 
stderr: E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) 
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root? 

我想我編輯指定AWS_ACCESS_KEYAWS_SECRET_KEY,但我找不到怎麼辦呢

回答

0

隨着錯誤消息E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?這意味着你需要運行與根ansible劇本。

你可以嘗試與sudo是嗎?

- hosts: 'all' 
    remote_user: 'ubuntu' 
    sudo: yes 
0

您可以使用它,因爲sudo: yes將很快棄用。

--- 
- hosts: 'all' 
    remote_user: 'ubuntu' 
    become: yes