1

I am new to using ansible and I am trying to set up a simple Hello world playbook. So far I have everything talking to each other but I can't seem to automate the nginx install. I have tried several variations and I can not seem to find any documentation for yum installing nginx with ansible.

My playbook looks like this: (Sorry for the formatting). It runs through the EPEL release install and seems to hang forever on the nginx install.

---
- hosts: webserver
  tasks:
      - name: Install EPEL release for nginx
        yum: name=epel-release state=present

      - name: Install nginx web server
        yum: name=nginx state=installed update_cache=true
        notify:
          - start nginx

      - name: Upload the default index.html file
        copy: src=html_files/index.html dest=/usr/share/nginx/www/ mode=0644

  handlers:
      - name: start nginx
        service: name=nginx enables=yes state=started

Any help would be greatly appreciated.

If I change line 8 to :

yum: name=http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm state=present

it runs fine.

Playbook output for the failing task:

TASK: [Install nginx web server] **********************************************
<54.67.19.159> ESTABLISH CONNECTION FOR USER: root
<54.67.19.159> REMOTE_MODULE yum name=nginx state=latest update_cache=true
<54.67.19.159> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/username/.ansible/cp/ansible-ssh-%h-%p-%r" -o IdentityFile="/Users/username/.ssh/pemfile.pem" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 54.67.19.159 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1427534955.48-246337214944853 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1427534955.48-246337214944853 && echo $HOME/.ansible/tmp/ansible-tmp-1427534955.48-246337214944853'
<54.67.19.159> PUT /var/folders/l0/5f3qkrxd1sn976dzb5sfkk640000gn/T/tmpczLCV7 TO /root/.ansible/tmp/ansible-tmp-1427534955.48-246337214944853/yum
<54.67.19.159> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/username/.ansible/cp/ansible-ssh-%h-%p-%r" -o IdentityFile="/Users/username/.ssh/pemfile.pem" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 54.67.19.159 /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python -tt /root/.ansible/tmp/ansible-tmp-1427534955.48-246337214944853/yum; rm -rf /root/.ansible/tmp/ansible-tmp-1427534955.48-246337214944853/ >/dev/null 2>&1'
Luke Peterson
  • 8,584
  • 8
  • 45
  • 46
seanm1985
  • 53
  • 2
  • 5
  • Oh, I am able to manually ssh in and run yum install nginx, then it runs and the Task says it changes, but nothing happens. – seanm1985 Mar 28 '15 at 06:52
  • 1
    please post the output of `ansible-playbook yourplaybook -vvvv` – ProfHase85 Mar 28 '15 at 08:31
  • @seanm1985, did you check the nginx service status,lile (sudo service nginx status) if it is running, then check your iptables rules please and open the port 80. – Arbab Nazar Mar 28 '15 at 08:57
  • @seanm1985 What user are you connecting as to the remote host? Does it have permissions to install packages? What does it look like on the server when Ansible hangs? – Mxx Mar 29 '15 at 22:16

2 Answers2

1

First Try with a ssh login connection to host without password. And change

 service: name=nginx enables=yes state=started 

into

 service: name=nginx enabled=yes state=started
The Hungry Dictator
  • 3,444
  • 5
  • 37
  • 53
0

@shilpa's answer is correct. To expand...

your issue isn't with the installation, it's with starting the service. you have a syntax error in your handler.

Explanation: here you have a task that installs the service then you notify your handler

  - name: Install nginx web server
    yum:
      name: nginx
      state: installed
      update_cache: yes
    notify:
      - start nginx

but your handler has an invalid attribute, enables. It needs to read, enabled. So your task above completes. The service is installed but idle. The handler is notified but perhaps an error is generated (or noop).

Corrected sample:

- name: short line lengths make easier to catch mistakes
  service:
    name: nginx
    enabled: yes
    state: started

I recommend, when learning ansible, to check the module page for every task you write or use a linter that would help sanity check your code as you're writing.

reference:

I would also recommend the generic package module over the yum one. Good luck and happy coding.

Camilo Santana
  • 334
  • 2
  • 7