Could not find file 'nssm.exe' - windows

I'm trying to autostart nginx from mac to windows2019 using ansible, but I get an error.
ansible [core 2.12.2]、
python version = 3.10.2
- name: install nginx
win_chocolatey:
name: nginx
version: 1.21.6
- name: Transfer nginx.conf
win_template:
src: ./win/nginx/nginx.conf
dest: C:\tools\nginx-1.21.6\conf\nginx.conf
- name: install nssm
win_chocolatey:
name: nssm
state: present
- name: start nginx
win_nssm:
name: nginx
application: C:\tools\nginx-1.21.6\nginx.exe
app_parameters_free_form: -c C:\tools\nginx-1.21.6\conf\nginx.conf -p C:\tools\nginx-1.21.6
stdout_file: C:\nginx_out.txt
stderr_file: C:\nginx_error.txt
start_mode: auto
state: started
notify:
- start nginx
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: at System.Management.Automation.CommandProcessorBase.Complete()
fatal: [XX.XXX.XXX.XX]: FAILED! => {"changed": false, "msg": "Unhandled exception while executing module: Exception calling \"SearchPath\" with \"1\" argument(s): \"Could not find file 'nssm.exe'.\""}
Sorry, it looks like you had to be an "Administrator" for the PATH to work.

Sorry, it looks like you had to be an "Administrator" for the PATH to work.
This worked.
- name: install nginx as service
become: yes
become_user: Administrator
become_method: runas
win_nssm:
name: nginx
application: C:\tools\nginx-1.21.6\nginx.exe
app_parameters_free_form: -c C:\tools\nginx-1.21.6\conf\nginx.conf -p C:\tools\nginx-1.21.6
stdout_file: C:\nginx_out.txt
stderr_file: C:\nginx_error.txt
start_mode: auto
state: started
notify:
- start nginx

Related

"Failure talking to yum: Cannot find a valid baseurl for repo: remi"

I am using the following ansible script to install php-fpm module in centOS but cannot figure out the error.
---
- hosts: all
become: yes
tasks:
- name: download remi release repo for php
get_url:
url: http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
dest: /tmp/remi-release-6.rpm
tags: php-fpm
- name: install remi repo
shell: /bin/rpm -Uvh /tmp/remi-release-6.rpm
register: remi_repo_result
failed_when: "'conflict' in remi_repo_result.stderr"
tags: php-fpm
- name: enable remi repo
ini_file: dest=/etc/yum.repos.d/remi.repo
section=remi
option=enabled
value=1
- name: install php-fpm and its deps
yum: name={{item}} state=present
with_items:
- php
- php-fpm
tags: php-fpm
- name: backup default php configuration
shell: /bin/cp /etc/php.ini /etc/php.default.ini creates=/etc/php.default.ini
tags: php-fpm
- name: display php errors when not in production
ini_file: dest=/etc/php.ini
section=PHP
option=display_errors
value=On
when: env is defined and env != "production"
notify:
- restart php-fpm
tags: php-fpm
- name: do not show php errors when in production
ini_file: dest=/etc/php.ini
section=PHP
option=display_errors
value=Off
when: env is defined and env == "production"
notify:
- restart php-fpm
tags: php-fpm
- name: backup default php-fpm configuration
shell: /bin/cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.default creates=/etc/php-fpm.d/www.conf.default
tags: php-fpm
- name: change php-fpm to listen on socket
ini_file: dest=/etc/php-fpm.d/www.conf
section=www
option=listen
value=/var/run/php-fpm/php-fpm.sock
notify:
- restart php-fpm
tags: php-fpm
- name: php-fpm listen mode should always be 0666
ini_file: dest=/etc/php-fpm.d/www.conf
section=www
option=listen.mode
value=0666
notify:
- restart php-fpm
tags: php-fpm
- name: change php-fpm user
ini_file: dest=/etc/php-fpm.d/www.conf
section=www
option=user
value=nginx
notify:
- restart php-fpm
tags: php-fpm
- name: change php-fpm group
ini_file: dest=/etc/php-fpm.d/www.conf
section=www
option=group
value=nginx
notify:
- restart php-fpm
tags: php-fpm
- name: start php-fpm
service: name=php-fpm state=running enabled=yes
tags: php-fpm
I get the following error in the task "install php-fpm and its deps"
failed: [127.0.0.1] (item=[u'php', u'php-fpm']) => {"ansible_loop_var": "item", "changed": false, "item": ["php", "php-fpm"], "msg": "Failure talking to yum: Cannot find a valid baseurl for repo: remi"}
Can someone help with a solution for this?
Note: most of the below is deduced from wild guesses since you did not provide a full and verbose run of the relevant tasks nor the values of the variables for the target you run the playbook against.
There are several issues with your above playbook, the most obvious and relevant one being that
- name: install remi repo
shell: /bin/rpm -Uvh /tmp/remi-release-6.rpm
register: remi_repo_result
failed_when: "'conflict' in remi_repo_result.stderr"
tags: php-fpm
is likelly to not fail although the command is in error.
And since you did not use create: false on the next ini_file task, /etc/yum.repos.d/remi.repo will still be created containing only
[remi]
enabled=1
(For this, I am of course assuming that env is not set or is different from production)
From there, the message you get is quite coherent since there is literally no base url for repo remi.
Some other notes you might want to take into account:
you can install a remote rpm with the yum module by directly passing the url as name
you should not loop over the yum module: pass the list of packages directly in the name attribute (see doc)
don't cp with shell, use the copy module with remote_src: true
Use the yaml syntax rather than ini style shortcut syntax

How to resolve ansible playbook error installing php "No package php-mysql available"?

I am trying to install Php, Apache in RHEL using the Ansible Playbook. But I am getting following error.
*failed: [18.191.65.251] (item=[u'php', u'php-mysql', u'php-pdo', u'php-gd', u'php-mbstring']) => {"ansible_loop_var": "item",
"changed": false, "failures": ["No package php-mysql available."],
"item": ["php", "php-mysql", "php-pdo", "php-gd", "php-mbstring"],
"msg": ["Failed to install some of the specified packages"], "rc": 1,
"results": []}
Screenshot of error
The code that I have used to write the playbook is as follows
---
- hosts: all
become: yes
tasks:
- name: Install httpd
yum:
name: httpd
state: present
- name: starting httpd service
service:
name: httpd
enabled: yes
state: started
- name: Installing php packages
yum:
name: "{{ item }}"
state: present
with_items:
- php
- php-mysql
- php-pdo
- php-gd
- php-mbstring
- name: restart Apache service
service:
name: httpd
state: restarted
Use Amazon Linux instead of RHEL, rest code will code work.
hosts: all
become: yes
tasks:
name: Install httpd
yum:
name: httpd
state: present
name: starting httpd service
service:
name: httpd
enabled: yes
state: started
name: Installing php packages
yum:
name: "{{ item }}"
state: present
with_items:
php
php-mysql
php-pdo
php-gd
php-mbstring
name: restart Apache service
service:
name: httpd
state: restarted

How to fix the ansible playbook error "Unsupported parameters for (systemd) module: enable Supported parameters?

I am trying to install Apache 2, PHP on Ubuntu machine using the ansible-playbook.
I am getting the following error
Error after executing playbook
fatal: [18.220.215.181]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (systemd) module: enable Supported parameters include: daemon_reexec, daemon_reload, enabled, force, masked, name, no_block, scope, state, user"}The ansible playbook is as follows---
- hosts: all
become: yes
tasks:
- name: Chenking ping
ping:
- name: Update packages
apt:
name: apache2
update_cache: yes
state: present
- name: restart apache2 server
service:
name: apache2
enable: yes
state: restarted
- name: install php module
apt:
name: "{{ item }}"
state: present
with_items:
- php
- libapache2-mod-php5
- php-mcrypt
- php-mysql
- name: restart apache2 afetr restart
service:
name: apache2
enable: yes
state: restarted
`
The right parameter is enabled (not enable) in your service tasks.
- name: restart apache2 afetr restart
service:
name: apache2
enabled: yes
state: restarted
Change "enabled" task containing service module.
- hosts: all
become: yes
tasks:
- name: Chenking ping
ping:
- name: Update packages
apt:
name: apache2
update_cache: yes
state: present
- name: restart apache2 server
service:
name: apache2
enabled: yes
state: restarted
- name: install php module
apt:
name: "{{ item }}"
state: present
with_items:
- php
- libapache2-mod-php5
- php-mcrypt
- php-mysql
I think last task is not required.

ansible role can't start apache via handler

I have this simple role for apache (in CentOS7):
roles/apache/tasks/main.yml
---
- name: Add epel-release repo
yum:
name: epel-release
state: present
- name: Install Apache2
yum:
name: httpd
state: present
- name: Insert Index Page
copy:
src: index.html
dest: /var/www/html/index.html
roles/apache/handlers/main.yml
---
- name: Start Apache
service: name=httpd state=started
- name: verify that the web service is running
command: systemctl status httpd
register: status_result
- name: debug
debug: var=status_result
with-roles.yml - playbook same level as 'roles' directory
---
- name: Install apache2 in CentOS 7
hosts: 1.23.4.56
become: true
roles:
- apache
I then run the playbook as follows:
$ ansible-playbook -u root --private-key ~/.ssh/this_key.ppk with-roles.yml -i "1.23.4.56" -vvvv
Here's the tail-end part of the verbose output on screen:
...
...
"mode": "0644",
"owner": "root",
"path": "/var/www/html/index.html",
"size": 11,
"state": "file",
"uid": 0
}
META: ran handlers
META: ran handlers
PLAY RECAP *******************************************************************************************************************
1.23.4.56 : ok=4 changed=0 unreachable=0 failed=0
but when I logged-in to 1.23.4.56, machine has the httpd installed but is stopped (which means that the handler didn't run). What am I doing wrong?
A handler is only executed when it's notified.
See Handlers: Running Operations On Change
The answer turns out to be in https://serverfault.com/questions/617548/always-trigger-handler-execution-in-ansible as per hints from René Pijl.
Specifically, I had to add this to the bottom of roles/apache/tasks/main.yml
...
...
- name: Apache Starter
command: /bin/true
notify: Start Apache

Why Ansible keeps giving me error "Could not find the requested service httpd: cannot check nor set state"?

I am doing a dry run on installing apache web server on a centos 7 box.
This is the webserver.yml file:
--- # Outline to Playbook Translation
- hosts: apacheWeb
user: aleatoire
sudo: yes
gather_facts: no
tasks:
- name: date/time stamp for when the playbook starts
raw: /bin/date > /home/aleatoire/playbook_start.log
- name: install the apache web server
yum: pkg=httpd state=latest
- name: start the web service
service: name=httpd state=started
- name: install client software - telnet
yum: pkg=telnet state=latest
- name: install client software - lynx
yum: pkg=lynx state=latest
- name: log all the packages installed on the system
raw: yum list installed > /home/aleatoire/installed.log
- name: date/time stamp for when the playbook ends
raw: /bin/date > /home/aleatoire/playbook_end.log
When I do a dry run with:
ansible-playbook webserver.yml --check
I keep getting this error:
fatal: [<ip_address>]: FAILED! => {"changed": false, "failed": true, "msg": "Could not find the requested service httpd: cannot check nor set state"}
to retry, use: --limit #/home/aleatoire/Outline/webserver.retry
I tried adding ignore_issues: true and that did not work either.
--check is not going to actually install the httpd package if it's not there yet. So then the service: call will fail if there is no httpd unit file installed yet.
You can use --syntax-check option instead.

Resources