Ansible parsing through list - ansible

I have a tower Template which when launched prompts users to provide hostname and it's IP separated by space per line. There will always be minimum two entries.
hostnameX ip_address
hostnameY ip_address
I am using the IP address and hostname to create DNS records in DNS servers in another task.
But for other task I just need the hostname and discard the IP address, and loop through the hostnames. But when I try
with_list: "{{list_serverinfo.split(' ')[0] }}"
The task is only run on hostnameX and never executes on hostnameY! I want the task to execute against all hostnames.
Thanks in advance for the time and all the help!

Related

how to switch a schedule task from one host to other in a cluster, when host that contain the schedule task is down in marklogic?

I scheduled a task in a bootstrap node in marklogic and but there might be chance that the host will down ,somehow ,in that case how I switched that task to other host in the cluster.
Note: I have to schedule the task only on a single host at a time from the cluster.
The options for assigning scheduled tasks are currently to set for a specific host, or to leave empty and have it execute on all hosts.
So, if you want to ensure that in the event of a host failure, the task is still executed, you could leave the host assignment empty and add logic inside of the task to determine which host should execute the code, and the others become a no-op.
An example of how to achieve that is to add code to the task to evaluate whether the xdmp:host() is the same host with the open Security forest (assuming that you have HA-replica forest for your Security DB to ensure availability, but could be achieved with any database)
xquery version "1.0-ml";
let $status := xdmp:database("Security") => xdmp:database-forests() => xdmp:forest-status()
where $status/*:host-id/data() eq xdmp:host()
return
(: this will only execute on the host with the open Security forest:)
"execute task logic"

Force ansible to apply changes on each lines of an inventory group

I have a bare metal server, and I want to install multiple services on this server.
My inventory looks like that
[Mygroup]
Server port_service=9990 service_name="service1"
Server port_service=9991 service_name="service2"
When I launch my ansible job,only service 2 is installed because I have the same server in each line of my group. There is way to force ansible to take all lines of a group?
I don't want to create a group for each service
Q: "There is a way to force Ansible to take all lines of a group?"
A: No. There is not. In a group, the hosts shall be unique. If there are multiple hosts with the same name the last one will be taken.
Put the variables into one line e.g.
[Mygroup]
Server port_services="[9990, 9991]" service_names="['service1', 'service2']"
(and change the code).
See How to build your inventory. There is a lot of other options e.g.
[Mygroup]
Server
[Mygroup:vars]
port_services="[9990, 9991]"
service_names="['service1', 'service2']"
I hope I got u right but this should do the trick.
https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html
Greets
Harry
Another solution is to use an alias.
This solution works fine for me
[Mygroup]
service_1 ansible_host=Server port_service=9990 service_name="service1"
service_2 ansible_host=Server port_service=9991 service_name="service2"

Using a synchronized counter variable ansible

My playbook is creating multiple instances of application in AWS.I want each of the instance to be tagged with a counter variable to maintain the count and id of each instance (do not want to use instance id and any other random id). Now , since the provisioning happens in parallel i am failing to get a consistent counter variable.
I have tried using a global variable to the play and incrementing it but it always returns the initial value as set fact is executed once.
I have also tried putting a variable in a file, reading and incrementing it for every host. This leads to race condition and i see same values for different hosts. Is there any way to do this.
Assuming that your ec2.ini file has
all_instances = True
to get stopped instances, they already ARE tagged, in a sense.
webserver[1] is always going to be the same host, until your inventory changes.
However, you can still tag your instances as you want, but if your inventory changes, it might be difficult to tag new instances with unique numbers.
- name: Loop over webserver instances and tag sequentially
ec2_tag:
state: present
tags:
myTag: "webserver{{item}}"
resource: "{{ hostvars[groups['webserver'][item|int]]['ec2_id'] }}"
with_sequence: start=0 end="{{ groups['webserver']|length - 1 }}"
delegate_to: localhost
N.B: item is a string, so we have to use [item|int] when pulling from the groups['webserver'] array.

Multiple postfix output IP

I have a server with multiple public IP addresses.
I want to send campaign emails on this server.
Sometimes i would like to send mail from a particular IP (it is a filter on the sender email address that gives which IP to use).
The only thing i find is to install multiple postfix instances (one per output IP). Is there a best way to do this ?
I have a second question: Postfix gives a unique queue id to each message. If i have several instances of postfix, do you think thoses uniques id can be the same in 2 postfix instances ?
Thanks
sender_dependent_default_transport_maps is your friend. First, add this to main.cf:
sender_dependent_default_transport_maps = hash:/etc/postfix/sender-transport
Next, create the file /etc/postfix/sender-transport with
#my-sender-domain.com smtp-192-168-0-1:
Any message received with sender #my-sender-domain.com will use the service smtp-192-168-0-1 (can be any name) for sending. Don't forget to postmap /etc/postfix/sender-transport the file.
And then, add the service to master.cf
smtp-192-168-0-1 unix - - n - - smtp
-o smtp_bind_address=192.168.0.1
Again, the service name can be anything, but it must match the one on the hash file. This smtp service will send the message from the IP 192.168.0.1. Change as needed.
Add as many services and lines in the hash file as you want. Don't forget to service postfix restart after that.
There are many other options you can add to the smtp service, like -o smtp_helo_name=my.public.hostname.com, etc.
I just finished to set up a postfix like this :-)

Multiple IP for One Host

I am setting up a grid-enabled cluster. I plan to assign 2 IP to my head node: one for local connection (LAN for distributing jobs to compute nodes) and one for public (internet for user access). So, my /etc/hosts file looks something like this:
111.111.111.111 myserver.whatever.com myserver #for public IP
11.11.11.11 myserver.whatever.com myserver #for local LAN
22.22.22.22 computenode01
33.33.33.33 computenode03
My concern here is will the hostname of myserver get messed up since it is mapped to two IPs?
I fear the system will always choose the first entry (111.111.111.111) if you want to resolve "myserver" address.
It will simply ignore the second entry, as I guess. Choose different hostnames for each entry, e.g. myserver.local and myserver.remote.

Resources