Running a exe file on windows server using ansible - ansible

I am using the below ansible playbooks but it's not installing it, can anyone help?
- name: Install Firefox
hosts: wintestserverchandra
**tasks:**
- name: Firefox
raw: d:\install\firefox.exe
I used win_msi as well but no go.

Seems that you want to install Firefox via Ansible.
Just use the chocolatey Firefox package and install it with the win_chocolatey module:
- name: Install Firefox via chocolatey
win_chocolatey:
name: Firefox

Related

Windows Package Creation with Ansible for Chocolatey

I'm new to Ansible and I'm trying to create a package to deploy to a Windows client running Chocolatey. I have all the winrm connections working between my ansible server and my windows client, but I am struggling to understand how to define and create packages.
As an example:
I want to install Notepad++ on the Windows client. I do not want it to connect to the internet to download the installer executable. Instead, I want the ansible server to push the exe to the client, then have the client execute it locally.
Can anyone explain and/or provide an example of a playbook to handle this? I know this is more easily achievable on windows via other products like SCCM, but for these purposes ansible is required.
The ansible playbook call you would look to make would look like such:
- name: Install notepadplusplus.install
win_chocolatey:
name: notepadplusplus.install
version: '8.4.5'
source: https:/YourInternalNuGetV2Repo
state: present
You would look to host the Chococlatey package on an internal NuGet V2 Repository
I think the part here that's missing is that you don't have a packages repository for Chocolatey to pull from. If you want to deploy a package with Chocolatey, it needs to get it from somewhere; the Ansible playbooks don't allow you to create packages directly and push them to machines, they mostly just allow you to setup Chocolatey and run Chocolatey commands.
If you want to build a Chocolatey package directly on the Ansible server, the Ansible modules for Chocolatey specifically don't have that functionality built in. You could potentially use other Ansible modules to construct the necessary script and zip files for the Chocolatey package, bundle in a targeted installer .exe, and upload it to the client. Not sure exactly how you'd do that, Ansible is generally for the deployment itelf moreso than packaging things for deployment.
Then, you could have the client instructed to install it by first adding the local folder that the package was uploaded to as a Chocolatey source:
win_chocolatey_source:
name: local
state: present
source: C:\\packages_folder
win_chocolatey:
name: package_name
source: local
state: latest
Instead, I want the ansible server to push the exe to the client, then have the client execute it locally.
If that is all you want then you don't need Chocolatey. Use win_copy to copy the EXE over from the server to the client and use something like win_command to execute it.
There are some caveats to it. You will need the command line arguments to make it run silently and headless. You'll need to test it all as some installers return immediately (and so control would return immediately to your playbook) even though they are still installing.
If you need to use Chocolatey then the other answers here are what you are looking for.

Ansible script to uninstall multiple versions of OMS agent

I wanted to do an uninstallation of OMS agent in our Linux machines. Unfortunately, we do have different OMS agent versions assigned to each machine. I hard coded the version from my Ansible script
command: sudo {{ file_path }}/omsagent-1.13.9-0.universal.x64.sh —-purge
It only works for machine with that same OMS agent version else, it will fail.
I tried adding wildcard syntax, but it is getting an error stating that command not found
stderr: “sudo :/home/filename/omsagent-* : command not found
if I changed my previous command to
command: sudo {{file_path}}/omsagent-*.universal.x64.sh —-purge
Since I do not have this specific agent in place, I can't provide a full tested working example, but some some guidance.
According the package documentation and All bundle operations, the bundle has an option for
--version-check Check versions already installed to see if upgradable.
which should provide the installed version. Furthermore any installed agent has an directory with service control script
/opt/microsoft/omsagent/bin/service_control ...
and probably others, like scxadmin --version. By executing one or the other it should be possible to gather the correct installed version of the agent.
- name: Gather installed OMS agent version
become: true
become_method: sudo
shell:
cmd: /opt/microsoft/omsagent/bin/service_control status | grep <whatever is necessary to get the version string only>
register: VERSION
changed_when: false
check_mode: false
Please take note that instead of using sudo within the command, you should use become. Since it is a version reporting task only, you should also use changed_when and check_mode.
After the correct version is gathered you use it like
- name: Purge installed OMS agent version
become: true
become_method: sudo
shell:
cmd: "omsagent-{{ VERSION }}.universal.x64.sh —-purge"
Is there any reason why the option --upgrade or --force can`t be used?
You may also have a look into How to troubleshoot issues with the Log Analytics agent for Linux, there is a standalone versionless purge script available.

win_package : passing arguments in the installation process

I am trying to install tomcat on win2016 server. I need to select Full install as an install type when i do it manually. How can i replicate the same in the win_package s an argument. I tried few options but it didn't work out. Appreciate the help. The Playbook will Succeed but the installation doesn't happen.
- name: install
win_package:
path: https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.62/bin/apache-tomcat-9.0.62.exe
product_id: '{2821726D-A54C-47AF-97C7-34666DF5DD0A}'
state: present
arguments:
- /type="Full"

python module firewall not found

computer run ansible-playbook: MacBook, with python 3.9
target machine: Debian 10 with python2.7.16 and python3.7.3
When I tried to open port in firewall:
- name: Open port 80 for http access
firewalld:
service: http
permanent: true
state: enabled
I got error:
fatal: [virtual_server]: FAILED! => {"changed": false, "msg": "Python
Module not found: firewalld and its python module are required for
this module, version 0.2.11 or newer required
(0.3.9 or newer for offline operations)"}
I also tried to use ansible.posix.firewall, with ansible-galaxy collection install ansible.posix on macbook, and use ansible.posix.firewall, still got this error.
Can anybody tell me what is wrong?
if you have your playbook vars like this
---
- hosts: testbench
vars:
ansible_python_interpreter: /usr/bin/python3
then your firewall task should be like this
- name: open ports
ansible.posix.firewalld:
permanent: true
immediate: true
port: "{{item}}/tcp"
state: enabled
become: true
vars:
ansible_python_interpreter: /usr/bin/python
with_items:
- tcp-port-1
- tcp-port-2
- tcp-port-3
ansible.posix.firewalld depends on the python firewalld bindings which are missing for the python version ansible is running under.
See https://bugzilla.redhat.com/show_bug.cgi?id=2091931 for a similar problem on systems using the EPEL8 ansible package, where the python3-firewall package is built against python 3.6 but ansible is using python 3.8.
ansible --version or head -1 $(which ansible) will tell you what version of Python ansible uses.
On redhat systems, dnf repoquery -l python3-firewall will tell you what version of Python python3-firewall is built against.
The solution is to install the appropriate python-firewalld package for your OS that matches the version of python ansible is using, if one exists.
If a compatible python-firewalld package does not exist, you can configure ansible to use a different version of python by setting the ansible_python_interpreter variable or the interpreter_python ansible.cfg setting (see https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html).
The problem is that you propably have awx installed on docker and he dont have that galaxy package do this :
1. go to main server
> docker images
find smt like this
ansible/awx 17.1.0 {here_id_of_image} 16 months ago 1.41GB
2. connect to that docker image
> docker run -it {here_id_of_image} bash
3. Run command to install pkg
> ansible-galaxy collection install ansible.posix
Done now run your playbook
I have fixed this problem by switch ansible_connection mode from paramiko to ssh on Ansible 5.10.0 x Ubuntu 22.04 .
My changes.
[ chusiang#ubuntu-22.04 ~ ]
$ vim ansible-pipeline.cfg
[defaults]
- ansible_connection = paramiko
- transport = paramiko
+ ansible_connection = ssh
+ transport = ssh
Ansible version.
[ chusiang#ubuntu-22.04 ~ ]
$ ansible --version
ansible [core 2.12.10]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/chusiang/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/chusiang/.local/lib/python3.10/site-packages/ansible
ansible collection location = /home/chusiang/.ansible/collections:/usr/share/ansible/collections
executable location = /home/chusiang/.local/bin/ansible
python version = 3.10.6 (main, Nov 2 2022, 18:53:38) [GCC 11.3.0]
jinja version = 3.0.3
libyaml = True
Pip versions of ansible.
[ chusiang#ubuntu-22.04 ~ ]
$ pip list | grep -i ansible
ansible 5.10.0
ansible-core 2.12.10
ansible-inventory-to-ssh-config 1.0.1
ansible-lint 3.5.1
Enjoy it.

Ansible Error : The lxc module is not importable. Check the requirements

My task looks something like this
- name: Create a started container
lxc_container:
name: test-container-started
container_log: true
template: ubuntu
state: started
template_options: --release trusty
I get the following errors:
> TASK: [lxc | Create a started container]
> **************************************  failed: [localhost] => {"failed": true, "parsed": false}
> BECOME-SUCCESS-azsyqtknxvlowmknianyqnmdhuggnanw failed=True msg='The
> lxc module is not importable. Check the requirements.' The lxc module
> is not importable. Check the requirements.
>
>
> FATAL: all hosts have already failed -- aborting
If you use Debian or Ubuntu as host system there is already python-lxc package available. The best way to install it is Ansible of course, just before lxc_container tasks:
tasks:
- name: Install provisioning dependencies
apt: name=python-lxc
- name: Create docker1.lxc container
lxc_container:
name: docker1
...
I just ran into the same issue andI solved it by making sure to pip install lxc-python2 system-wide on the target machine.
In my case the target was localhost via an ansible_connection=local host and I thought I could get away with pip: name=lxc-python2, but that installed into my current virtualenv.
lxc_container is relatively new.
To run the lxc_container module you need to make sure the pip package is installed on the target host, as well as lxc.
e.g
pip install lxc-python2
apt-get install lxc
The correct answer to the issue is to add:
become: yes
just before the lxc_container -module section, so as to get root privileges to run lxc-commands on target host.
Definitely not is it required to install any python2-lxc -support libs to target hosts to use lxc_container module, which requires such support to be available in management host only. Only the python2 must be available in the target host to be usable with current Ansible versions.
See ansible documention for more info about the requirements about the lxc-container module: (on host that executes module)
lxc >= 1.0 # OS package
python >= 2.6 # OS Package
lxc-python2 >= 0.1 # PIP Package from https://github.com/lxc/python2-lxc

Resources