2016-04-07 40 views
5

我正在使用Ansible創建AWS用戶。 Ansible的其中一項功能是使用訪問密鑰創建用戶。我想知道如何在成功創建用戶後獲取訪問密鑰。如何使用Ansible的iam_module獲取訪問密鑰?

http://docs.ansible.com/ansible/iam_module.html

tasks: 
- name: Create two new IAM users with API keys 
    iam: 
    iam_type: user 
    name: "{{ item }}" 
    state: present 
    password: "{{ temp_pass }}" 
    access_key_state: create 
    with_items: 
    - user 
+0

你是什麼ansible版本? – helloV

+0

2.0.0.2是最新版本 – Istvan

+0

它可能在2,0,0,2。註冊結果並嘗試。看到我的答案。 – helloV

回答

5

我試着在2.0.1.0。應該在2.0.0.2中工作。

tasks: 
    - iam: 
     iam_type: user 
     name: foo 
     state: present 
     access_key_state: create 
    register: credentials 
    - debug: var=credentials 

輸出

[debug] ******************************************************************* 
ok: [127.0.0.1] => { 
    "credentials": { 
     "changed": false, 
     "groups": null, 
     "keys": { 
      "AKIAXXXXXXXXXXTTGFXX": "Active" 
     }, 
     "user_name": "foo" 
    } 
} 

這是不可能得到的祕密作爲Ansible 2.0.1.0的。這是一個錯誤。見iam module not very useful for managing access keys

+0

你認爲你也可以獲得密鑰的祕密部分嗎?它僅在創建時可用。 – Istvan

+2

現在不可能得到這個祕密。查看我的更新。 – helloV

+0

您正在顯示訪問密鑰但未顯示密鑰。 http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html – Istvan

1

同時(我用Ansible 2.3.2.0),這一問題已成功固定:

- name: Create restricted bot user to access S3 
    iam: 
    iam_type: user 
    name: blubaa 
    state: present 
    access_key_state: create 
    connection: local 
    register: credentials 

- debug: var=credentials 

輸出:

ok: [XXXXXXXXXX] => { 
    "credentials": { 
     "changed": true, 
     "groups": null, 
     "keys": [ 
      { 
       "access_key_id": "AKIAJXXXXXXXXXXZX6GQ", 
       "create_date": "2017-08-26T01:04:05Z", 
       "status": "Active", 
       "user_name": "blubaa" 
      } 
     ], 
     "user_meta": { 
      "access_keys": [ 
       { 
        "access_key_id": "AKIAJXXXXXXXXXXZX6GQ", 
        "access_key_selector": "XXXX", 
        "create_date": "2017-08-26T01:04:05.720Z", 
        "secret_access_key": "wPwd2H0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXkHB08Elo", 
        "status": "Active", 
        "user_name": "blubaa" 
       } 
      ], 
      "created_user": { 
       "arn": "arn:aws:iam::30XXXXXXXXXX:user/blubaa", 
       "create_date": "2017-08-26T01:04:05.557Z", 
       "path": "/", 
       "user_id": "AIDAXXXXXXXXXXOYT7M", 
       "user_name": "blubaa" 
      }, 
      "password": null 
     } 
    } 
} 
相關問題