15
votes

I'm very new to Ansible. I am trying to follow a tutorial on the concept of Roles in Ansible. I have the following Master Playbook:

--- # Master Playbook for Webservers
- hosts: apacheweb
  user: test
  sudo: yes
  connection: ssh
  roles:
    - webservers

Which refers to the webservers role that has the following task/main.yml:

- name: Install Apache Web Server
  yum: pkg=httpd state=latest
  notify: Restart HTTPD

And a handler/main.yml:

- name: Restart HTTPD
  service: name=httpd state=started

When I execute the Master Playbook, mentioned above, I get the following error:

TASK [webservers : Install Apache Web Server] **********************************
fatal: [test.server.com]: FAILED! => {"changed": false, "failed": true, "msg": "The following packages have pending transactions: httpd-x86_64", "rc": 128, "results": ["The following packages have pending transactions: httpd-x86_64"]}

I cannot understand what this error corresponds to. There does not seem to be anything similar, based on my research, that could suggest the issue with the way I am using the Yum module.

NOTE: Ansible Version:

ansible 2.2.1.0
  config file = /etc/ansible/ansible.cfg
3

3 Answers

34
votes

It seems there are unfinished / pending transactions on the target host. Try installing yum-utils package to run yum-complete-transaction to the target hosts giving the error.

# yum-complete-transaction --cleanup-only

Look at Fixing There are unfinished transactions remaining for more details.

yum-complete-transaction is a program which finds incomplete or aborted yum transactions on a system and attempts to complete them. It looks at the transaction-all* and transaction-done* files which can normally be found in /var/lib/yum if a yum transaction aborted in the middle of execution.

If it finds more than one unfinished transaction it will attempt to complete the most recent one first. You can run it more than once to clean up all unfinished transactions.

1
votes

Unfinished transaction remaining

sudo yum install yum-utils

yum-complete-transaction --cleanup-only

0
votes

I am using for ansible this type of config for the playbooks:

- name: Install Apache Web Server
  yum: name=httpd state=latest
  notify: Restart HTTPD

As far as i know there is no such option as yum: pkg=httpd in ansbile for the yum module (if I'm not wrong, that pkg=httpd is for apt-get on debian based distros)

If you need to install multiple packages you could use something like:

- name: "Install httpd packages"
  yum: name={{ item }} state=present
  with_items:
    - httpd
    - httpd-devel
    - httpd-tools

Of course you can change the state=present to state=latest or whatever option might suits you best

http://docs.ansible.com/ansible/yum_module.html - ansible documentation for yum module