Ansible:“shell”不执行

发布于 2025-01-09 20:52:41 字数 514 浏览 1 评论 0原文

我正在尝试运行 shell 命令来安装从本地 Artifactory 存储库下载的包,因为我无权直接从互联网下载它。

当我直接在节点上运行命令时,

rpm -ivh kubectl-1.1.1.x86_64.rpm --nodigest --nofiledigest

它工作得很好。

但随后将其放入 Ansible 剧本中,

- name: Install Kubectl
  shell: rpm -ivh kubectl-1.1.1.x86_64.rpm --nodigest --nofiledigest

什么也没有发生。

它没有错误..它只是无法安装。

我也尝试了 commandansible.builtin.shell 模块,但没有任何效果。

请问有办法做到这一点吗?

I'm trying to run a shell command to install a package downloaded from my local Artifactory repository, as I don't have access to download it straight from the internet.

When I run the command directly on the node as such

rpm -ivh kubectl-1.1.1.x86_64.rpm --nodigest --nofiledigest

It works perfectly.

But then put in Ansible playbook as such

- name: Install Kubectl
  shell: rpm -ivh kubectl-1.1.1.x86_64.rpm --nodigest --nofiledigest

Nothing happens.

It doesn't error.. It just doesn't install.

I've tried the command and ansible.builtin.shell module as well, but nothing works.

Is there a way to do this please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毅然前行 2025-01-16 20:52:41

你的问题有不同的主题。

关于

安装从本地 Artifactory 存储库下载的软件包,因为我无法直接从互联网下载它。

您可以使用不同的方法。

1.直接下载

- name: Make sure package becomes installed from internal repository
  yum:
    name: https://{{ REPOSITORY_URL }}/artifactory/kube/kubectl-{{ KUBE_VERSION }}.x86_64.rpm
    state: present

2.配置本地存储库

下一个是提供一个 .repo 模板文件,例如

[KUBE]
name = Kubectl - $basearch
baseurl = https://{{ REPOSITORY_URL }}/artifactory/kube/
username = {{ API_USER }}
password = {{ API_KEY }}
sslverify = 1
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-KUBE

和 来执行

- name: Make sure package becomes installed from internal repository
  yum:
    name: kubectl
    state: present

这是可能的,因为如果配置正确,JFrog Artifactory 可以提供本地 RPM 存储库。有关更多信息,您可以研究那里的文档,因为它几乎只涉及正确的配置。

关于

什么也没发生。它没有错误..它只是没有安装。

您可以使用多个任务来拆分您的步骤,使它们具有幂等性并更好地了解它们的工作原理。

3. shellrpmdebug

- name: Make sure destination folder for package download (/opt/packages) exists
  file:
    path: "/opt/packages/"
    state: directory

- name: Download RPM to remote hosts
  get_url:
    url: "https://{{ REPOSTORY_URL }}/artifactory/kube/kubectl-{{ KUBE_VERSION }}.x86_64.rpm"
    dest: "/opt/packages/kubectl-{{ KUBE_VERSION }}.x86_64.rpm"
 
- name: Check package content
  shell:
    cmd: "rpm -qlp /opt/packages/kubectl-{{ KUBE_VERSION }}.x86_64.rpm"
  register: rpm_qlp

- name: STDOUT rpm_qlp
  debug: 
    msg: "{{ rpm_qlp.stdout.split('\n')[:-1] }}"

- name: Install RPM using 'command: rpm -ivh'
  shell:
    cmd: "rpm -ivh /opt/packages/kubectl-{{ KUBE_VERSION }}.x86_64.rpm"
  register: rpm_ivh

- name: STDOUT rpm_ivh
  debug: 
    msg: "{{ rpm_ivh.stdout.split('\n')[:-1] }}"

根据 RPM 软件包、环境和配置,所有这些都可能运行良好。

There are different topics in your question.

Regarding

to install a package downloaded from my local Artifactory repository, as I don't have access to download it straight from the internet.

you can use different approaches.

1. Direct download

- name: Make sure package becomes installed from internal repository
  yum:
    name: https://{{ REPOSITORY_URL }}/artifactory/kube/kubectl-{{ KUBE_VERSION }}.x86_64.rpm
    state: present

2. Configure local repository

The next one is to provide a .repo template file like

[KUBE]
name = Kubectl - $basearch
baseurl = https://{{ REPOSITORY_URL }}/artifactory/kube/
username = {{ API_USER }}
password = {{ API_KEY }}
sslverify = 1
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-KUBE

and to perform

- name: Make sure package becomes installed from internal repository
  yum:
    name: kubectl
    state: present

This is possible because JFrog Artifactory can provide local RPM repositories if configured correctly. For more information you research the documentation there since it is almost only about proper configuration.

Regarding

Nothing happens. It doesn't error.. It just doesn't install.

you can use several task to split up your steps, make them idempotent and get an better insight how they are working.

3. shell, rpm and debug

- name: Make sure destination folder for package download (/opt/packages) exists
  file:
    path: "/opt/packages/"
    state: directory

- name: Download RPM to remote hosts
  get_url:
    url: "https://{{ REPOSTORY_URL }}/artifactory/kube/kubectl-{{ KUBE_VERSION }}.x86_64.rpm"
    dest: "/opt/packages/kubectl-{{ KUBE_VERSION }}.x86_64.rpm"
 
- name: Check package content
  shell:
    cmd: "rpm -qlp /opt/packages/kubectl-{{ KUBE_VERSION }}.x86_64.rpm"
  register: rpm_qlp

- name: STDOUT rpm_qlp
  debug: 
    msg: "{{ rpm_qlp.stdout.split('\n')[:-1] }}"

- name: Install RPM using 'command: rpm -ivh'
  shell:
    cmd: "rpm -ivh /opt/packages/kubectl-{{ KUBE_VERSION }}.x86_64.rpm"
  register: rpm_ivh

- name: STDOUT rpm_ivh
  debug: 
    msg: "{{ rpm_ivh.stdout.split('\n')[:-1] }}"

Depending on the RPM package, environment and configuration, all may just work good.

酸甜透明夹心 2025-01-16 20:52:41

尝试使用 command 模块并注册输出,我使用它在 Linux 上为 Oracle 数据库安装 pecl 的 oci8

Try use command module and register the output i use it to install oci8 by pecl for oracle database on linux

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文