Body: <p>I'm currently working with a centos5 host and I have to install some packages with yum.</p>
  <p>Unfortunately, as far as I know, centos5 doesn't support Ansible's yum module, since it requires python2 bindings, which are obsolete, so I have to use the <code>command</code> or <code>shell</code> modules and 'hard code' everything by myself.</p>
  <p>My question is: what are the conditions I should implement to make a command/shell behave like Ansible's yum module and make it as much 'idempotent' as possible?</p>
  <p>For the moment this is what I came up with:</p>
  <h3>When installing/updating a package</h3>
  <pre class="lang-yaml prettyprint-override"><code>- name: INSTALL (C5) - Install package
    ansible.builtin.command:
      cmd: yum -y install &lt;package&gt;
    register: output_install
    changed_when: '&quot;Installing:&quot; in output_install[&quot;stdout&quot;] or &quot;Updating:&quot; in output_install[&quot;stdout&quot;]'
    failed_when: output_install[&quot;stdout&quot;] is regex(&quot;No package.*available&quot;)
  </code></pre>
  <h3>When removing a package</h3>
  <pre class="lang-yaml prettyprint-override"><code>- name: UNINSTALL (C5) - Remove package
    ansible.builtin.command:
      cmd: yum -y remove &lt;package&gt;
    register: output_remove
    changed_when: '&quot;Erasing&quot; in output_remove[&quot;stdout&quot;]
    failed_when: &quot;No Packages marked for removal&quot; in output_remove[&quot;stdout&quot;]'
  </code></pre>
  <p>Do you have any suggestion or have already dealt with this problem?</p>
  <p>Thank you very much.</p>
  
Comments: CC BY-SA 4.0
Comments: 2022-12-20T09:53:07.650Z
Comments: > centos5 doesn't support Ansible's yum module
  
  can you provide some evidence for this statement? A link, an error, something?
Comments: Bruce Becker
Comments: CC BY-SA 4.0
Comments: 2022-12-20T17:14:08.557Z
Comments: @BruceBecker you can see on this [post](https://stackoverflow.com/questions/48429110/centos-5-ansible-python-interpreter-usr-bin-python26-still-cannot-use-yum-mo), someone else already reported this issue
Comments: Wander
Comments: CC BY-SA 4.0
Comments: 2022-12-20T17:38:11.853Z
Comments: I've tried to reproduce this a bit with a centos5 container, but it's just too old and unsupported. The logic looks correct in your failed_ and changed_when though. I would answer the question yourself, with the "proof" showing the actual yum output
Comments: Bruce Becker
Tags: <ansible><linux><centos>
Title: Implementing the right conditions for a yum command for centos5 in Ansible
UserDisplayName: Wander
ThreadText: # Implementing the right conditions for a yum command for centos5 in Ansible
  
  (Asked by: username_0 on 2022-11-14)
  
  I'm currently working with a centos5 host and I have to install some packages with yum.
  
  Unfortunately, as far as I know, centos5 doesn't support Ansible's yum module, since it requires python2 bindings, which are obsolete, so I have to use the `command` or `shell` modules and 'hard code' everything by myself.
  
  My question is: what are the conditions I should implement to make a command/shell behave like Ansible's yum module and make it as much 'idempotent' as possible?
  
  For the moment this is what I came up with:
  
  ### When installing/updating a package
  
  ```yaml
  - name: INSTALL (C5) - Install package
    ansible.builtin.command:
      cmd: yum -y install <package>
    register: output_install
    changed_when: '"Installing:" in output_install["stdout"] or "Updating:" in output_install["stdout"]'
    failed_when: output_install["stdout"] is regex("No package.*available")
  
  ```
  
  ### When removing a package
  
  ```yaml
  - name: UNINSTALL (C5) - Remove package
    ansible.builtin.command:
      cmd: yum -y remove <package>
    register: output_remove
    changed_when: '"Erasing" in output_remove["stdout"]
    failed_when: "No Packages marked for removal" in output_remove["stdout"]'
  
  ```
  
  Do you have any suggestion or have already dealt with this problem?
  
  Thank you very much.
  
  **Tags:** ansible, linux, centos
  
  > **Comments:**
  > **username_1**: > centos5 doesn't support Ansible's yum module  can you provide some evidence for this statement? A link, an error, something?  
  > **username_0**: @username_1 you can see on this [post](https://stackoverflow.com/questions/48429110/centos-5-ansible-python-interpreter-usr-bin-python26-still-cannot-use-yum-mo), someone else already reported this issue  
  > **username_1**: I've tried to reproduce this a bit with a centos5 container, but it's just too old and unsupported. The logic looks correct in your failed_ and changed_when though. I would answer the question yourself, with the "proof" showing the actual yum output  
  
  ---
  
  ## 0 answers
  
  