Migrating playbook from ubuntu to amazon linux 2 - throws error missing dependency: python-apt

73 views
Skip to first unread message

Work-Hard

unread,
Feb 4, 2020, 8:08:01 PM2/4/20
to Ansible Project
Hello,
Do you recommend Migrating playbook from ubuntu to amazon Linux 2 (as it uses yum instead of apt). If so, how can I check if missing add a package to a new instance to make sure it installs python-apt?
Ansible-Playbook
---
- hosts: amazonlinux2
  become: true
  any_errors_fatal: true
  serial: 1
  max_fail_percentage: 0
  vars:
    ansible_user: ec2-user
  tasks:
    # do an "apt-get update", to ensure latest package lists
    - name: apt-get update
      apt:
        update-cache: yes
      changed_when: 0

    # get a list of packages that have updates
    - name: get list of pending upgrades
      command: apt-get --simulate dist-upgrade
      args:
        warn: false # don't warn us about apt having its own plugin
      register: apt_simulate
      changed_when: 0

    - name: Update cache
      apt:
        update-cache: yes
      changed_when: false

    - name: Fetch package list of updates
      command: apt list --upgradable
      register: aptlist

    - set_fact:
        updates: "{{ aptlist.stdout_lines | difference(['Listing...'])
| map('regex_replace', '^(.*?)/(.*)', '\\1') | list }}"

    - debug: var=updates

    # tell user about packages being updated
    - name: show pending updates
      debug:
        var: updates
      when: updates.0 is defined

    # comment this part in if you want to manually ack each server update
    - pause:
      when: updates.0 is defined

    # if a new kernel is incoming, remove old ones to avoid full /boot
    - name: apt-get autoremove
      command: apt-get -y autoremove
      args:
        warn: false
      when: '"Inst linux-image-" in apt_simulate.stdout'
      changed_when: 0

    # do the actual apt-get dist-upgrade
    - name: apt-get dist-upgrade
      apt:
        upgrade: dist # upgrade all packages to latest version
      register: upgrade_output

    # check if we need a reboot
    - name: check if reboot needed
      stat: path=/var/run/reboot-required
      register: file_reboot_required

    # "meta: end_play" aborts the rest of the tasks in the current «tasks:»
    # section, for the current webserver
    # "when:" clause ensures that the "meta: end_play" only triggers if the
    # current server does _not_ need a reboot
    - meta: end_play
      when: not file_reboot_required.stat.exists

    # because of the above meta/when we at this point know that the current
    # host needs a reboot

    # prompt for manual input before doing the actual reboot
    - name: Confirm reboot of ec2-user
      pause:

    - name: reboot node
      shell: sleep 2 && shutdown -r now "Reboot triggered by ansible"
      async: 1
      poll: 0
      ignore_errors: true

    # poll ssh port until we get a tcp connect
    - name: wait for node to finish booting
      become: false
      local_action: wait_for host=ec2-user
          port=22
          state=started
          delay=5
          timeout=600

    # give sshd time to start fully
    - name: wait for ssh to start fully
      pause:
        seconds: 15

    # wait a few minutes between hosts, unless we're on the last
    - name: waiting between hosts
      pause:
        minutes: 10
      when: inventory_hostname != ansible_play_hosts[-1]


Ansible-Output
PLAY [amazonlinux2] ******************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************
[WARNING]: Platform linux on host 10.11.12.13 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python
interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.

ok: [10.11.12.13]

TASK [apt-get update] ****************************************************************************************************************************************
[WARNING]: Updating cache and auto-installing missing dependency: python-apt

fatal: [10.11.12.13]: FAILED! => {"changed": false, "cmd": "apt-get update", "msg": "[Errno 2] No such file or directory", "rc": 2}

NO MORE HOSTS LEFT *******************************************************************************************************************************************

NO MORE HOSTS LEFT *******************************************************************************************************************************************

PLAY RECAP ***************************************************************************************************************************************************
10.11.12.13                 : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0


Stefan Hornburg (Racke)

unread,
Feb 5, 2020, 3:06:52 AM2/5/20
to ansible...@googlegroups.com
On 2/5/20 2:08 AM, Work-Hard wrote:
> Hello,
> Do you recommend Migrating playbook from ubuntu to amazon Linux 2 (as it uses *yum instead of apt*). If so, how can I
> check if missing add a package to a new instance to make sure it installs python-apt*?*
> *Ansible-Playbook*

If Amazon Linux2 is a RedHat based distribution (as the usage of yum suggests) it makes no sense to
use python-apt as it caters to Debian based distributions.

Regards
Racke
> *
> *
> *Ansible-Output*
> PLAY [amazonlinux2]
> ******************************************************************************************************************************************
>
> TASK [Gathering Facts]
> ***************************************************************************************************************************************
> [WARNING]: Platform linux on host 10.11.12.13 is using the discovered Python interpreter at /usr/bin/python, but future
> installation of another Python
> interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html
> for more information.
>
> ok: [10.11.12.13]
>
> TASK [apt-get update]
> ****************************************************************************************************************************************
> [WARNING]: Updating cache and auto-installing *missing dependency: python-apt*
>
> fatal: [10.11.12.13]: FAILED! => {"changed": false, "cmd": "apt-get update", "msg": "[Errno 2] No such file or
> directory", "rc": 2}
>
> NO MORE HOSTS LEFT
> *******************************************************************************************************************************************
>
> NO MORE HOSTS LEFT
> *******************************************************************************************************************************************
>
> PLAY RECAP
> ***************************************************************************************************************************************************
> 10.11.12.13                 : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
>
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/32e8f062-4e24-400e-a7d7-2f2181d9c8f4%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/32e8f062-4e24-400e-a7d7-2f2181d9c8f4%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Dick Visser

unread,
Feb 5, 2020, 3:27:26 AM2/5/20
to ansible...@googlegroups.com
On Wed, 5 Feb 2020 at 09:06, Stefan Hornburg (Racke) <ra...@linuxia.de> wrote:
>
> On 2/5/20 2:08 AM, Work-Hard wrote:
> > Hello,
> > Do you recommend Migrating playbook from ubuntu to amazon Linux 2 (as it uses *yum instead of apt*). If so, how can I
> > check if missing add a package to a new instance to make sure it installs python-apt*?*
> > *Ansible-Playbook*
>
> If Amazon Linux2 is a RedHat based distribution (as the usage of yum suggests) it makes no sense to
> use python-apt as it caters to Debian based distributions.

Also, the package management isn't the only difference between Debian
and Redhat based distros.
So if you have any other playbooks that have implicitly Debianisms you
will need to rewrite those as well.
Things that come to mind are the ways packages themselves are
configured - config file location and inclusion structure, the init
system etc.




--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Adrian Sebastian Dutu

unread,
Feb 5, 2020, 3:48:01 AM2/5/20
to Ansible Project
Why are you using the command module?

Use the package module. Then it will not matter what package manager the distro is running.
If you have ansible module available for what you want to do, never use command. I would rewrite the entire play.

Stefan Hornburg (Racke)

unread,
Feb 5, 2020, 4:27:01 AM2/5/20
to ansible...@googlegroups.com
On 2/5/20 9:48 AM, Adrian Sebastian Dutu wrote:
> Why are you using the command module?
>
> Use the package module. Then it will not matter what package manager the distro is running.
> If you have ansible module available for what you want to do, never use command. I would rewrite the entire play.
>

You can use the package module, but it will not be able to list packages and the names of packages might
differ between different distros etc.

Regards
Racke

>
>
> On Wednesday, February 5, 2020 at 2:08:01 AM UTC+1, Work-Hard wrote:
>
> Hello,
> Do you recommend Migrating playbook from ubuntu to amazon Linux 2 (as it uses *yum instead of apt*). If so, how can
> I check if missing add a package to a new instance to make sure it installs python-apt*?*
> *Ansible-Playbook*
> *
> *
> *Ansible-Output*
> PLAY [amazonlinux2]
> ******************************************************************************************************************************************
>
> TASK [Gathering Facts]
> ***************************************************************************************************************************************
> [WARNING]: Platform linux on host 10.11.12.13 is using the discovered Python interpreter at /usr/bin/python, but
> future installation of another Python
> interpreter could change this. See
> https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html
> <https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html> for more information.
>
> ok: [10.11.12.13]
>
> TASK [apt-get update]
> ****************************************************************************************************************************************
> [WARNING]: Updating cache and auto-installing *missing dependency: python-apt*
>
> fatal: [10.11.12.13]: FAILED! => {"changed": false, "cmd": "apt-get update", "msg": "[Errno 2] No such file or
> directory", "rc": 2}
>
> NO MORE HOSTS LEFT
> *******************************************************************************************************************************************
>
> NO MORE HOSTS LEFT
> *******************************************************************************************************************************************
>
> PLAY RECAP
> ***************************************************************************************************************************************************
> 10.11.12.13                 : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
>
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/21203f8f-5383-47e9-ad8e-feb8cf8cb34f%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/21203f8f-5383-47e9-ad8e-feb8cf8cb34f%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc

Work-Hard

unread,
Feb 5, 2020, 5:07:00 PM2/5/20
to Ansible Project
So, I am breaking it down in the playbook -  it doesn't like spaces in name of the package?
playbook:
---
- hosts: amazonlinux2
  become: true
  any_errors_fatal: true
  serial: 1
  max_fail_percentage: 0
  vars:
    ansible_user: ec2-user
  tasks:
    # do an "yum update", to ensure latest package lists
    - name: yum update
      package:
        name: yum update
        state: present
        update_cache: true

Out-put:
fatal: [10.0.2.144]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "allow_downgrade": false,
            "autoremove": false,
            "bugfix": false,
            "conf_file": null,
            "disable_excludes": null,
            "disable_gpg_check": false,
            "disable_plugin": [],
            "disablerepo": [],
            "download_dir": null,
            "download_only": false,
            "enable_plugin": [],
            "enablerepo": [],
            "exclude": [],
            "install_repoquery": true,
            "install_weak_deps": true,
            "installroot": "/",
            "list": null,
            "lock_timeout": 30,
            "name": [
                "yum update"
            ],
            "releasever": null,
            "security": false,
            "skip_broken": false,
            "state": "present",
            "update_cache": true,
            "update_only": false,
            "use_backend": "auto",
            "validate_certs": true
        }
    },
    "msg": "It appears that a space separated string of packages was passed in as an argument. To operate on several packages, pass a comma separated string of packages or a list of packages."
}





Dick Visser

unread,
Feb 5, 2020, 5:54:22 PM2/5/20
to ansible...@googlegroups.com
Correct.
There is no package called "yum update".
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/52fb9d1c-b2ee-4861-93b4-7439b6bf6ab5%40googlegroups.com.

Work-Hard

unread,
Feb 5, 2020, 6:28:27 PM2/5/20
to Ansible Project
Thanks for the update. I was able to figure it out!

Adrian Sebastian Dutu

unread,
Feb 6, 2020, 8:44:44 AM2/6/20
to Ansible Project
Reply all
Reply to author
Forward
0 new messages