2015-12-21 56 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