RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 784925
Accepted
faoxis
faoxis
Asked:2020-02-14 15:29:33 +0000 UTC2020-02-14 15:29:33 +0000 UTC 2020-02-14 15:29:33 +0000 UTC

在 ansible 脚本中添加新存储库

  • 772

我需要执行以下命令集ansible:

apt-get update && apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl

问题从第二行开始。通过ansible我这样做:

- name: curl curl
  command: sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

作为回应,我收到一个错误:

 [WARNING]: Consider using 'become', 'become_method', and 'become_user' rather
than running sudo

fatal: [default]: FAILED! => {"changed": true, "cmd": ["sudo", "curl", "-s", "https://packages.cloud.google.com/apt/doc/apt-key.gpg", "|", "sudo", "apt-key", "add", "-"], "delta": "0:00:00.037295", "end": "2018-02-14 07:25:50.272885", "failed": true, "msg": "non-zero return code", "rc": 2, "start": "2018-02-14 07:25:50.235590", "stderr": "curl: option -: is unknown\ncurl: try 'curl --help' or 'curl --manual' for more information", "stderr_lines": ["curl: option -: is unknown", "curl: try 'curl --help' or 'curl --manual' for more information"], "stdout": "", "stdout_lines": []}

如何正确执行这样的命令?我试图在命令中添加一行sudo: true并将其删除sudo。错误不会消失。

linux
  • 2 2 个回答
  • 10 Views

2 个回答

  • Voted
  1. A K
    2020-02-14T15:38:19Z2020-02-14T15:38:19Z

    让我们按顺序走吧。这只是一个警告,一个警告。Ansible 提示您重新制作 bash 命令,因为它会在其中看到单词 sudo 并告诉您“嘿,我也可以 sudo - 使用我的常规方式。”

    可以忽略。

    如果你想使用 ansible 的标准特性,那么你需要着眼于成为:

    ---
    # This playbook deploys 'webserver' server.
    
    - include: init_server.yml
    
    - name: deploy 'webserver'
      hosts: '{{ target | default("webservers") }}'
      become: true
      become_user: root
      roles:
        - nginx
        - httpd
        - { role: webtatic_repository, when: r_php.version == "5.6" }
        - php
    

    同时,在 ansible.cfg 中指定要连接到机器的用户(并非所有 playbook 都需要 become_user: root 对我来说),例如:

    [defaults]
    sudo_flags=-HE
    remote_user = ansible
    retry_files_enabled = false
    

    纯看历史:之前没有become命令,remote_user是和sudo结合使用的,所以如果你遇到很老的文章,可以在里面看到这个命令:

    ---
    # This playbook deploys 'webserver' server.
    
    - name: deploy 'webserver'
      hosts: '{{ target }}'
      remote_user: user
      sudo: true
      roles:
        - nginx
    

    在我的实践中,有一种情况是我忽略了关于用 ansible rsync 模块替换 rsync shell 命令的 ansible 警告:我首先使用来自 ansible 的标准 rsync 命令准确地编写了一个任务,但结果证明它不支持一些支持线 rsync 命令的模式/键。因此,我在评论中单独描述了这种非标准脚本的原因,以便有人不会破坏脚本,试图“改进”它 - 但总的来说我尽量减少从命令行启动的使用。

    在您的情况下,我建议在没有命令行游戏的情况下切换到apt_repository 。

    • 1
  2. Best Answer
    don Rumata
    2020-02-15T05:29:24Z2020-02-15T05:29:24Z

    好吧,我猜是这样的:

    - name: Install Kubernetes 4 Ubuntu
      when: ansible_distribution == 'Ubuntu'
      become: yes
      block:
        - apt:
            name: apt-transport-https
            state: latest
        - apt_repository:
            repo: deb http://apt.kubernetes.io/ kubernetes-{{ ansible_distribution_release }} main
            state: present
            filename: kubernetes
            update_cache: no
        - apt_key:
            url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
            state: present
        - apt:
            update_cache: yes
            force: yes
        - apt:
            name:
              - kubelet
              - kubeadm
              - kubectl
            state: present
            install_recommends: yes
    
    • 1

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    是否可以在 C++ 中继承类 <---> 结构?

    • 2 个回答
  • Marko Smith

    这种神经网络架构适合文本分类吗?

    • 1 个回答
  • Marko Smith

    为什么分配的工作方式不同?

    • 3 个回答
  • Marko Smith

    控制台中的光标坐标

    • 1 个回答
  • Marko Smith

    如何在 C++ 中删除类的实例?

    • 4 个回答
  • Marko Smith

    点是否属于线段的问题

    • 2 个回答
  • Marko Smith

    json结构错误

    • 1 个回答
  • Marko Smith

    ServiceWorker 中的“获取”事件

    • 1 个回答
  • Marko Smith

    c ++控制台应用程序exe文件[重复]

    • 1 个回答
  • Marko Smith

    按多列从sql表中选择

    • 1 个回答
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Suvitruf - Andrei Apanasik 什么是空? 2020-08-21 01:48:09 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5