通过Ansible安装AWS-IAM-authenticator

时间:2019-03-07 18:58:11

标签: amazon-web-services ansible

寻找如何(正确地)从bash命令(Dockerfile中的原始文件)转换为ansible任务/角色,该任务/角色将下载最新的aws-iam-authenticator二进制文件并安装到Ubuntu(x64)OS上的/ usr / local / bin中

目前我有:

curl -s https://api.github.com/repos/kubernetes-sigs/aws-iam-authenticator/releases/latest | grep "browser_download.url.*linux_amd64" | cut -d : -f 2,3 | tr -d '"' | wget -O /usr/local/bin/aws-iam-authenticator -qi - && chmod 555 /usr/local/bin/aws-iam-authenticator

3 个答案:

答案 0 :(得分:1)

基本上,您需要编写一本剧本并将该命令分隔在各种任务中

示例example.yml文件

- hosts: localhost
  tasks:
  - shell: |
      curl -s https://api.github.com/repos/kubernetes-sigs/aws-iam-authenticator/releases/latest
    register: json
  - set_fact:
      url: "{{ (json.stdout | from_json).assets[2].browser_download_url }}"
  - get_url:
      url: "{{ url }}"
      dest: /usr/local/bin/aws-iam-authenticator-ansible
      mode: 0555

您可以通过执行

来执行它
ansible-playbook --become example.yml

我希望这是您正在寻找的;-)

答案 1 :(得分:1)

因此,在找到其他提示,信息和未解决问题的帖子后,Ansible - Download latest release binary from Github repohttps://github.com/ansible/ansible/issues/27299#issuecomment-331068246。我能够提出以下对我有用的艰巨任务。

   - name: Get latest url for linux-amd64 release for aws-iam-authenticator
     uri:
       url: https://api.github.com/repos/kubernetes-sigs/aws-iam-authenticator/releases/latest
       return_content: true
       body_format: json
     register: json_response

   - name: Download and install aws-iam-authenticator
     get_url:
       url:  " {{ json_response.json | to_json | from_json| json_query(\"assets[?ends_with(name,'linux_amd64')].browser_download_url | [0]\") }}"
       mode: 555
       dest: /usr/local/bin/aws-iam-authenticator

答案 2 :(得分:0)

Note 如果您运行的是 AWS CLI 版本 1.16.156 或更高版本,则无需安装身份验证器。相反,您可以使用 aws eks get-token 命令。有关详细信息,请参阅 Create kubeconfig manually