Ansible: Using Different OS to Deploy

I MUST be doing something wrong. I am completely at a loss.

I’m building out some Ansible playbooks on Ubuntu. When testing the playbooks on CentOS, they return “OK” (basically saying everything worked). However, when I go into /var/log/yum.log, the package manager wasn’t run. When I run yum update I can see that there are packages pending.

Digging at Ansible a bit, I see it’s using apt and dpkg to do things. That’s weird. So I jump on Fedora and run the exact same playbook – And it’s using dnf.

What the hell is going on? You HAVE to be on the same host as you’re deploying to? That can’t be right. Everything I’ve heard about this tool I never once heard anyone say anything about that.

I’ve seen some ways to override certain package managers, but everyone is saying not to do it.

Any advice? Hints? Tips?

2 Likes

Got it, it was a

MOTHER F’ING SYNTAX ISSUE

:smiley: :smiley: :smiley:

Former

- hosts: admindev
  remote_user: adev
  become: yes
  become_method: sudo

tasks:
  - name: Update Node.js
    yum:
      name: nodejs
      state: latest

Fix’d

---
 - hosts: admindev
  remote_user: adev
  become: yes
  become_method: sudo

  tasks:
          - name: Update Node.js
            yum: pkg=nodejs state=latest

:+1:

Good shite. I’ve never run into this because I’ve always gone from Ubuntu to Debian. Which, if apt and dpkg is the default I never would’ve noticed lmao.

/rekt

@SgtAwesomesauce :stuck_out_tongue_winking_eye:

1 Like

So, you removed the hosts line?

Unless you were trying to hit a host that wasn’t admindev, I don’t see why that would have made a difference.

Also, it doesn’t matter what OS you’re running ansible from, as long as it has ssh and python.

Hell, you could deploy from Windows if you’re in a self-loathing mood.

No, I don’t know why that’s showing up in red. I added the three dashes at the top and put the yum on one line, with the pkg assignment.

Added a space in the code to prevent confusion :wink:

Yeah, none of that should make a difference.

Are you using tabs or spaces in your editor? You should be using spaces.

EDIT: nevermind, we have the --- in our ansible scripts, but this is how it looks for us:


I’d recommend using the “package” module, rather than yum/apt/etc… You don’t have to change the code for a different distro.
1 Like

So you’re saying both files should work?

Because when I do this:

  - name: Update Node.js
    yum:
      name: nodejs
      state: latest

It uses apt and looks for dpkg-lock

When I do this:

  tasks:
          - name: Update Node.js
            yum: pkg=nodejs state=latest

It actually runs yum install nodejs

It’s the season of being thankful, appreciative, and grateful for what I have, but don’t test me with this :stuck_out_tongue: :stuck_out_tongue_winking_eye: :wink:

Good question, when I manually make the entries I am using spaces. However, when have a colon and I press enter, my vim configuration will automatically indent – no idea what vim is doing.

That definitely shouldn’t be happening. :confused:

Oh, if you’re using vim, it’s spaces.

1 Like

I’ll try the yum: name: thing again with the triple dash and see if that works. It was very bizarre, and I don’t remember doing that at work.

Good to know!

I <3 vim

Thanks for sharing your source! I’ll try and mimic that and see what happens.

If you’re having issues with that, ditch “yum” and use “package”

https://docs.ansible.com/ansible/latest/modules/package_module.html

These should be equivalent:

  tasks:
  - name: Update Node.js
    yum: pkg=nodejs state=latest
  tasks:
    - name: Update Node.js
      yum:
        pkg: nodejs
        state: latest

https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html#action-shorthand