Ansible uri module - powershell

I have web url and i have two options enable/disable , Now I am writing ansible playbook to do this which is in Powershell script
My ansible playbook
---
- hosts: localhost
vars:
applauncher: "xweb"
jobState: "Disable"
serverName: "NETBATCH"
jobName: "Loan1"
tasks:
- name: edit app jobs
uri:
url: 'http://{{ applauncher }}/Edit/{{ jobState }}?Server={{ serverName }}&JobName={{ jobName }}'
method: POST
user: xxxx
password: xxx
I am passing extra vars to disable and enable option , Is it possible to use this option in uri module and which method I should use to select disable/enable option in URL

I think this is what you are after, but it took me a while to figure out what you are asking for. Read about vars_prompt playbook keyword: https://docs.ansible.com/ansible/latest/user_guide/playbooks_prompts.html

Related

Running GitHub scripts directly from Rundeck

I have a Windows server running the community version of Rundeck, and I want to be able to run PowerShell scripts directly from my private GitHub repository, by providing the URL of the script.
On GitHub, I have created a personal access token that doesn't expire, because I'm running multiple jobs on Rundeck and I don't want to be modifying each job, every time a token expires.
I've tried various ways to do this but nothing works.
providing the username and password in the URL
providing the username and access token in the URL
https://$username:$token#raw.githubusercontent.com/$username/general/main/rundeck/$script.ps1
https://$username:$password#raw.githubusercontent.com/$username/general/main/rundeck/$script.ps1
I know that at some point GitHub disabled password authentication in the URL, so I'm looking for an alternative way to do it.
If it's possible I don't want to clone the git repository. I want to use a link to the raw script and run it directly.
It works in the following way:
On GitHub Go to your Avatar icon (up to right) > Settings > Developer Settings (left menu) > Personal Access Token > Tokens.
Click on the "Generate new token" button (up to right) > Generate new token (classic). Make sure to create a token with enough rights to read your repository. Save this token value.
On Rundeck, create a new job and add "Script file or URL", on the "File Path/URL" field put the remote path with the following format: https://<your_github_user_name>:<your_user_token>#raw.githubusercontent.com/username/repository/branch/your_script.sh
I made a job definition example that works (tested on Rundeck 4.8.0):
- defaultTab: nodes
description: ''
executionEnabled: true
id: 5f74a444-7b2f-4e50-af96-ca770c9d038e
loglevel: INFO
name: RemoteScriptTest
nodeFilterEditable: false
plugins:
ExecutionLifecycle: null
scheduleEnabled: true
sequence:
commands:
- fileExtension: .sh
interpreterArgsQuoted: false
scriptInterpreter: /bin/bash
scripturl: https://user:my_user_token#raw.githubusercontent.com/user/scripts/main/myscript.sh
keepgoing: false
strategy: node-first
uuid: 5f74a444-7b2f-4e50-af96-ca770c9d038e
This example calls a bash script but you can use Powershell to define powershell.exe on the "Invocation String" and .ps1 on the "File extension" text boxes.
Note: if you want to use an option to store the token, use the ${option.myoption} format, here is another example:
- defaultTab: nodes
description: ''
executionEnabled: true
id: 5f74a444-7b2f-4e50-af96-ca770c9d038e
loglevel: INFO
name: RemoteScriptTest
nodeFilterEditable: false
options:
- name: mytoken
value: abc123
plugins:
ExecutionLifecycle: null
scheduleEnabled: true
sequence:
commands:
- fileExtension: .sh
interpreterArgsQuoted: false
scriptInterpreter: /bin/bash
scripturl: https://user:${option.mytoken}#raw.githubusercontent.com/user/scripts/main/myscript.sh
keepgoing: false
strategy: node-first
uuid: 5f74a444-7b2f-4e50-af96-ca770c9d038e

How do I use Ansible's "include_vars" with a GitHub file?

I have a YML file stored in a private GitHub repository and am trying to use Ansible's include_vars module to upload these variables in the playbook_dir.
The tasks responsible for this behavior are all passing however, a later job is failing due to one of the variables being undefined. Which makes me think that I am not correctly adding the values to the directory.
My task.yml file looks like:
---
- name: Ensure the application directory exists
win_file:
path: '{{ playbook_dir }}'
state: directory
- name: Download vars file from VCS
win_get_url:
url: 'https://raw.githubusercontent.com/<org>/<repo>/main/<path-to-file>/DEV1.yml?token=<temp raw file token>'
dest: '{{ playbook_dir }}/DEV1.yml'
force: true
register: result
- name: Include vars file for deployment
include_vars:
dir: '{{ playbook_dir }}'
files_matching: DEV1.yml
register: varfile
- debug:
msg: '{{ varfile }}'
After running this, the console output for the debug task is:
12:35:27 TASK [get_vars : debug] ********************************************************
12:35:27
12:35:27 {"failed":false,"ansible_included_var_files":[],"ansible_facts":{},"changed":false}
Am I not able to download files from GitHub through Ansible?

User Environment Variable with airflow.webserver.defaultUser.password

I am using the Helm chart for Apache Airflow and trying to set the password of the default user to the value of an environment variable:
airflow:
env:
- name: PASSWORD
value: Hello, World!
webserver:
defaultUser:
password: $PASSWORD
However, this is setting the password to literally $PASSWORD instead of Hello, World!.
I have tried other things like password: ${PASSWORD} to no avail.
Use as follow, this is as described in official examples.
$(PASSWORD)

How to use Azure DevOps server (TFS) Predefined Variable in My Ansible Playbook?

I want to use Azure DevOps Predefine Variable "$(Build.SourcesDirectory)" in My playbook:
Here is my playbook:
---
- hosts: KBR_MTL361
tasks:
- name: copy file
win_copy:
src: D:\Web.config
dest: $(Build.SourcesDirectory)
I am running this ansible-playbook using Azure DevOps Pipeline:
TFS Pipeline Task
But it is not working
Is there anyone who has any idea how to use the variable in the pipeline?
Just add your variables as additional args in the azure-pipelines.yml like this:
- task: Ansible#0
inputs:
ansibleInterface: 'agentMachine'
playbookPathOnAgentMachine: 'ansible/tfs_playbooks/install_agent.yml'
inventoriesAgentMachine: 'file'
inventoryFileOnAgentMachine: 'hosts.yml'
args: '--extra-vars "build_source_dir=$(Build.SourcesDirectory) AGENT_URL=$(AGENT_URL)"'
Then you can access the variables in your playbook:
---
- hosts: localhost
tasks:
- name: show debug
debug:
msg: "Dir {{ build_source_dir }} agent url {{AGENT_URL}}"
if you look here: https://daniel-krzyczkowski.github.io/Parameters-In-Azure-DevOps-Pipelines there is a certain way to pass Pipeline variables to a powershell script, for instance:
[CmdletBinding()]
param (
$ApiManagementServiceName,
$ApiManagementServiceResourceGroup
)
$apimServiceName = $ApiManagementServiceName
$resourceGroupName = $ApiManagementServiceResourceGroup
Write-Host "Api Management Service Name: $($apimServiceName)"
Write-Host "Api Management Resource Group Name: $($resourceGroupName)"
you are using still powershell you say, so give this a try or try to do something similar that works in your case, for me the above approach works pretty well in standard powershell.

How to add parameters to the included task files in Concourse CI

If task file (file: task.yml) in pipeline (pipeline.yml) config needs to contain some {{properties}}, what is a proper way to add them?
In my case, I want to use a custom docker image from repository that uses authentication, and I don't want to hardcode/commit credentials in task yml itself.
Is the a way to do that currently without moving task config to the main pipeline yml?
Clarification: I want to parameterize task.yml file itself (for example, input: {{input_name}}).
In your task.yml you can specify required params, e.g:
params:
USERNAME:
PASSWORD:
And then provide them in pipeline.yml:
jobs:
- name: my-job
plan:
- get: ci-files
- task: my-task
file: ci-files/task.yml
params:
USERNAME: {{username}}
PASSWORD: {{password}}
Configure pipeline as:
fly set-pipeline -p pipeline-name -c pipeline.yml -v=USERNAME=my-username -v=PASSWORD=my-password
Then these params will be available to you as environment variables inside your task.