简体   繁体   English

kubectl 完成 bash 与 Ancible

[英]kubectl completion bash with Ancible

I am new to ansible, please bear with me.我是 ansible 的新手,请多多包涵。

I have the following shell commands for bash completion.我有以下 shell 命令用于 bash 完成。

I want to achieve that with Ansible.我想用 Ansible 来实现。

apt-get install net-tools bash-completion -y
kubectl completion bash >/etc/bash_completion.d/kubectl
echo 'source <(kubectl completion bash)' >> /etc/bashrc

I am stuck with the middle one.我被中间那个困住了。 The first and last I know how to write in Ansible.第一个也是最后一个我知道如何在 Ansible 中编写。

kubectl completion bash >/etc/bash_completion.d/kubectl

Basically as I understand(I am new to bash scripting as well) the output to the command基本上据我了解(我也是 bash 脚本的新手)命令的 output

kubectl completion bash 

should be written to the file /etc/bash_completion.d/kubectl应该写入文件 /etc/bash_completion.d/kubectl

It should be simple I guess.我猜应该很简单。 If some one can nudge me in the right direction, it would be helpful.如果有人可以将我推向正确的方向,那将很有帮助。

The Ansible command module will not work, as stated in the doc: Ansible 命令模块将不起作用,如文档中所述:

The command(s) will not be processed through the shell, so variables like $HOSTNAME and operations like "*", "<", ">", "|", ";"命令将不会通过 shell 处理,因此 $HOSTNAME 等变量和“*”、“<”、“>”、“|”、“;”等操作and "&" will not work.而“&”将不起作用。

You should rather take a look at Ansible shell module , especially the examples provided.您应该看一下Ansible shell 模块,尤其是提供的示例

Something like this should do the trick:这样的事情应该可以解决问题:

- name: Execute the command in remote shell and write the output in the specified remote file
  ansible.builtin.shell:
    cmd: kubectl completion bash > /etc/bash_completion.d/kubectl
    # If you do not want to run this when the file already exists, add
    creates: /etc/bash_completion.d/kubectl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM