[ansible-project] Generate temaplate file when having with_items and array
I need to generate few files based on jinja template , In the first run it is easy when I need to generate single file per user *Basic input:* user: - { username: user1, action: get , file: 1.txt } - { username: user2, action: get , file: 2.txt } *Jinja template:* User: {{ item.users }} Permission: {{ item.action}} File-access: {{ite.file}} *Playbook:* - name: generate files template: src: template.j2 dest: "{{ folder }}/{{ item.username }}" with_items: "{{ user }}" But now comes the twist, Single user can have multi files (see user1) and , I need to create for this user 2 files File 1 – filename user1-1 , where file = to 1.txt File 2 – filename user1-2 , where file = to new.file *Advance input:* user: - { username: user1, action: get , file: [1.txt ,new.file] } - { username: user2, action: get , file: 2.txt } Any ideas ? -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f4ece24c-9706-4ccb-89bf-1ae8b18d9d34n%40googlegroups.com.
[ansible-project] Jinja template cannot fetch '0.10' value
Hi, I have input file that include the following parameter. *internal_network_reverse*: 0.10 and a jinja template file that include the following line zone "{{ *internal_network_reverse *| default ('168.192') }}.in-addr.arpa" The *required output* I wish to get is zone "*0.10*.in-addr.arpa" *Instead*, I’m getting this zone "*0.1*.in-addr.arpa" ; *Without the zero * I have tried using string and float but still I’m not getting the required result. zone "{{ internal_network_reverse | *string *| default ('168.192') }}.in-addr.arpa" zone "{{ internal_network_reverse | *float *| default ('168.192') }}.in-addr.arpa" Any suggestions?? *Please note that I don’t want to add “ “ in my input file - this way it is working but I need to avoid the use of “ “ -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7d07272f-c396-465d-931c-381c2a4e92a7n%40googlegroups.com.
[ansible-project] Copy from remote server to local
Hi , 1. Is there an option to copy full folder from remote server to local server ? 2. Copy all files under a folder located in remote server to a folder on local server - without running find job that register all files As i understand Fetch is for single file or multi files that can be run in a loop -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fab6d58a-198d-4826-b4c5-0d4678390dadn%40googlegroups.com.
Re: [ansible-project] Loop files that will be used as variables
Vladimir Botka@ Thank you - it works ב-יום ראשון, 18 ביוני 2023 בשעה 09:51:58 UTC+3, Vladimir Botka כתב/ה: > On Wed, 14 Jun 2023 04:07:38 -0700 (PDT) > "dudu.c...@gmail.com" wrote: > > > *My J2 file* > > > > select * from {{ item.id}} where {{ item.color}} > > > > *My input files* > > > > *File-1.yml :* > > Id: 1 > > color: blue > > > > *File-2**.yml** :* > > Id: 2 > > color: red > > > > *My Playbook – that is not working. * > > - hosts: localhost > > become: true > > gather_facts: yes > > tasks: > > - name: > > template: > > src: /opt/input.sql.j2 > > dest: /opt//{{item.id}}.sql > > with_items: > > - file-1.yaml > > > > - file-2.yaml > > > > *The output files I wish to have * > > > > 1.sql > > select * from 1 where blue > > > > 2.sql > > select * from 2 where red > > Given the files > > shell> cat file-1.yaml > id: 1 > color: blue > > shell> cat file-2.yaml > id: 2 > color: red > > Read the files in the loop. Test it > > shell> cat pb.yml > - hosts: localhost > tasks: > - debug: > var: i > loop: > - file-1.yaml > - file-2.yaml > vars: > i: "{{ lookup('file', item )|from_yaml }}" > > gives (abridged) > > TASK [debug] > > ok: [localhost] => (item=file-1.yaml) => ansible_loop_var: item > i: > color: blue > id: 1 > item: file-1.yaml > ok: [localhost] => (item=file-2.yaml) => > ansible_loop_var: item > i: > color: red > id: 2 > item: file-2.yaml > > The variable *item* keeps the name of the current file in the loop. > You have to use the variable *i* both in the template file > > shell> cat input.sql.j2 > select * from {{ i.id }} where {{ i.color }} > > and in the *template* task. The play > > shell> cat pb.yml > - hosts: localhost > tasks: > - template: > src: input.sql.j2 > dest: "/tmp/{{ i.id }}.sql" > loop: > - file-1.yaml > - file-2.yaml > vars: > i: "{{ lookup('file', item )|from_yaml }}" > > creates the files > > shell> cat /tmp/1.sql > select * from 1 where blue > > shell> cat /tmp/2.sql > select * from 2 where red > > > -- > Vladimir Botka > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/34a83ba2-7f1c-4f21-bdb7-8af8bca633e5n%40googlegroups.com.
Re: [ansible-project] Loop files that will be used as variables
Sorry - But i didnt fully understand your question My input files are static - The problem that i'm trying to solve is how to loop "vars_file" for the same task ב-יום רביעי, 14 ביוני 2023 בשעה 22:01:56 UTC+3, Will McDonald כתב/ה: > I think this answer might give you a pointer in the right direction: > https://stackoverflow.com/a/52237675 > > It should work, but there could be a better/simpler way to do this. Do you > control the generation of the files that provide your source variables? > > What's the *actual *problem you need to solve? (Obviously dynamically > generating and presumably running some SQL but can you step back a level or > two and describe the actual goal?) > > > On Wed, 14 Jun 2023 at 12:07, dudu.c...@gmail.com > wrote: > >> Hi , >> >> >> I’m using the template module that takes a J2 template and update the >> relevant fields. >> >> My problem is When I want to create a file per file input should be used >> as variable – I’m actually need to understand how to loop file that should >> be used as var files >> >> >> *My J2 file* >> >> select * from {{ item.id}} where {{ item.color}} >> >> >> >> *My input files* >> >> *File-1.yml :* >> >> Id: 1 >> color: blue >> >> >> >> *File-2**.yml** :* >> >> Id: 2 >> color: red >> >> >> >> *My Playbook – that is not working. * >> >> >> >> - hosts: localhost >> become: true >> gather_facts: yes >> tasks: >> - name: >> template: >> src: /opt/input.sql.j2 >> dest: /opt//{{item.id}}.sql >> with_items: >> - file-1.yaml >> >> - file-2.yaml >> >> >> >> >> >> *The output files I wish to have * >> >> 1.sql >> >> select * from 1 where blue >> >> >> >> 2.sql >> >> select * from 2 where red >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ansible Project" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to ansible-proje...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/ansible-project/50d4e830-9330-43be-95dc-68795a311d9an%40googlegroups.com >> >> <https://groups.google.com/d/msgid/ansible-project/50d4e830-9330-43be-95dc-68795a311d9an%40googlegroups.com?utm_medium=email_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/809b9f8d-9440-43f0-8a4c-64baab6eb0a9n%40googlegroups.com.
[ansible-project] Loop files that will be used as variables
Hi , I’m using the template module that takes a J2 template and update the relevant fields. My problem is When I want to create a file per file input should be used as variable – I’m actually need to understand how to loop file that should be used as var files *My J2 file* select * from {{ item.id}} where {{ item.color}} *My input files* *File-1.yml :* Id: 1 color: blue *File-2**.yml** :* Id: 2 color: red *My Playbook – that is not working. * - hosts: localhost become: true gather_facts: yes tasks: - name: template: src: /opt/input.sql.j2 dest: /opt//{{item.id}}.sql with_items: - file-1.yaml - file-2.yaml *The output files I wish to have * 1.sql select * from 1 where blue 2.sql select * from 2 where red -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/50d4e830-9330-43be-95dc-68795a311d9an%40googlegroups.com.
[ansible-project] how to present the following structure in more elegant way - such a table
Hi , I have an input file that i'm using as part of J2 template. Is there more elegant way to present the configuration inside the input file - for example a solution like a table ? group_configuration: rootGroups: working: hardConcurrencyLimit: 100 maxQueued: 1000 interactive: hardConcurrencyLimit: 80 maxQueued: 800 background: hardConcurrencyLimit: 20 maxQueued: 200 base: hardConcurrencyLimit: 15 maxQueued: 150 scheduled: hardConcurrencyLimit: 5 maxQueued: 50 non_working: hardConcurrencyLimit: 100 maxQueued: 1000 interactive: hardConcurrencyLimit: 20 maxQueued: 200 background: hardConcurrencyLimit: 80 maxQueued: 800 base: hardConcurrencyLimit: 15 maxQueued: 150 scheduled: hardConcurrencyLimit: 5 maxQueued: 50 -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/72e3bc8a-a105-48f4-888a-a95b70f029e9n%40googlegroups.com.
Re: [ansible-project] how to include template file inside other template file ?
Thank you for the answer - It is working But . When i'm managing both *main.conf.j2 *and *extra.conf.j2 *under the same folder everything works - But when i'm moving *main.conf.j2 *to a different folder (/opt) and updating the template accordingly i'm getting an error that file can not be found *# extra.conf.j2* number.of.server = {{ num_of_servers.input }} {% include '*/opt/*main.conf.j2' %} ב-יום שני, 23 בינואר 2023 בשעה 00:52:34 UTC+2, uto...@gmail.com כתב/ה: > It's actually quite easy to include or import .j2 templates into other > .j2 templates. There are some subtle and nuanced differences which you > should understand before you go much further, but in your case a simple > include will do the trick. > > *# main.conf.j2* > > *memory = {{ memory.input }}**cpu = {{ cpu.input }}**domain = {{ domain.input > }}* > > and > > *# extra.conf.j2**number.of.server = {{ num_of_servers.input }}**{% include > 'main.conf.j2' %}* > > That's it. You were within a few characters of the answer in your original > question. > > > On 1/22/23 1:54 AM, dudu.c...@gmail.com wrote: > > I have a template file called *main.conf.j2* and this is distributed to > all of my servers. There additional server that need to have a single > configuration that should include the configuration of the *main.conf.j2* > file and additional configuration – I have named the file *extra.conf.j2* > > > > My question is if there is a way to import the main.conf.j2 file inside > the extra.conf.j2? the reason is that in case of a changes in the > main.conf.j2 I want to manage only a single file > > > > *main.conf.j2* – only in example > > memory = {{memory.input}} > > cpu = {{cpu.input}} > > domain = {{domain.input}} > > > > *extra.conf.j2* – only in example > > number.of.server = {{num_of_servers.input}} > > < here I want to include the main.conf.j2> > > > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7050c7db-ac06-4a96-8ee1-1f80eb56ac80n%40googlegroups.com.
[ansible-project] how to include template file inside other template file ?
I have a template file called *main.conf.j2* and this is distributed to all of my servers. There additional server that need to have a single configuration that should include the configuration of the *main.conf.j2* file and additional configuration – I have named the file *extra.conf.j2* My question is if there is a way to import the main.conf.j2 file inside the extra.conf.j2? the reason is that in case of a changes in the main.conf.j2 I want to manage only a single file *main.conf.j2* – only in example memory = {{memory.input}} cpu = {{cpu.input}} domain = {{domain.input}} *extra.conf.j2* – only in example number.of.server = {{num_of_servers.input}} < here I want to include the main.conf.j2> -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/afac1df8-306a-42b2-9c96-ba766bb454f6n%40googlegroups.com.
[ansible-project] Looking for a string inside a register
i’m running an API call in order to get indexes in Elastic – The output is saved inside a registry (index_list). I want to run an additional job that runs only in case the policy name can be found in the register output – The solution I gave is not working (I’m guessing that I need to loop inside the registry on specific fields ) - in the example below i have a policy ID named *what* *API Call* - name: Get ISM_retention policy uri: url: http://elastic:9200/_opendistro/_ism/policies method: GET timeout: 180 body_format: json register: index_list *The debug condition that I’m trying to run –* In the register output you can find the *u'policy_id': u'what'* - debug: msg: hello when: “'what' in index_list” *The register output* MSG: (I have marked the policy ID in bold) {u'status': 200, u'content_length': u'1919', u'cookies': {}, u'url': u'http://elastic:9200/_opendistro/_ism/policies', u'changed': False, u'elapsed': 0, u'failed': False, u'json': {u'total_policies': 3, u'policies': [{u'policy': {u'default_state': u'hot', u'description': u'policy for delete index', u'last_updated_time': 1667984798760, u'error_notification': None, u'states': [{u'transitions': [{u'conditions': {u'min_index_age': u'1d'}, u'state_name': u'delete'}], u'name': u'hot', u'actions': [{u'retry': {u'count': 3, u'delay': u'1m', u'backoff': u'exponential'}, u'open': {}}]}, {u'transitions': [], u'name': u'delete', u'actions': [{u'retry': {u'count': 3, u'delay': u'1m', u'backoff': u'exponential'}, u'delete': {}}]}], u'ism_template': [{u'index_patterns': [u'audit-*'], u'priority': 100, u'last_updated_time': 1667984798760}], u'schema_version': 15, u'policy_id': u'policy_1'}, u'_id': u'policy_1', u'_seq_no': 104149, u'_primary_term': 1}, {u'policy': {u'default_state': u'hot', u'description': u'kuku index retenation flow', u'last_updated_time': 1668061803458, u'error_notification': None, u'states': [{u'transitions': [{u'conditions': {u'min_index_age': u'1d'}, u'state_name': u'delete'}], u'name': u'hot', u'actions': [{u'retry': {u'count': 3, u'delay': u'1m', u'backoff': u'exponential'}, u'open': {}}]}, {u'transitions': [], u'name': u'delete', u'actions': [{u'retry': {u'count': 3, u'delay': u'1m', u'backoff': u'exponential'}, u'delete': {}}]}], u'ism_template': [{u'index_patterns': [u'kuku-*'], u'priority': 100, u'last_updated_time': 1668061803458}], u'schema_version': 15, u'policy_id': u'policy_kuku'}, u'_id': u'policy_kuku', u'_seq_no': 143284, u'_primary_term': 1}, {u'policy': {u'default_state': u'hot', u'description': u'what index retenation flow', u'last_updated_time': 1668074528411, u'error_notification': None, u'states': [{u'transitions': [{u'conditions': {u'min_index_age': u'1d'}, u'state_name': u'delete'}], u'name': u'hot', u'actions': [{u'retry': {u'count': 3, u'delay': u'1m', u'backoff': u'exponential'}, u'open': {}}]}, {u'transitions': [], u'name': u'delete', u'actions': [{u'retry': {u'count': 3, u'delay': u'1m', u'backoff': u'exponential'}, u'delete': {}}]}], u'ism_template': [{u'index_patterns': [u'what-*'], u'priority': 100, u'last_updated_time': 1668074528411}], u'schema_version': 15, *u'policy_id': u'what'*}, u'_id': u'what', u'_seq_no': 150078, u'_primary_term': 1}]}, u'content_type': u'application/json; charset=UTF-8', u'msg': u'OK (1919 bytes)', u'redirected': False, u'cookies_string': u''} -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/778370c9-e4dd-4743-b559-61aa2fcbede7n%40googlegroups.com.
[ansible-project] finding a specific port on a list of servers
HI, I have a list of servers that only part of them are running port 9090. I need to create two tasks, each should loop the server's hostnames. the first task should define inside a register the first server hostname that was found running port 9090 , the second task should define in a register all server's hostnames that are running port 9090. If no server is running port 9090 the tasks should fail I have nc installed on the server and i thought about using a shell with the command "nc -zv {{ item}} 9090 But I don't know how to filter the relevant answers For example: server1 server2 server3 running 9090 server4 server5 running 9090 - The first task should include in a register server 3 *or* server 5 hostname - The second task should include in a register server 3 *and *server 5 hostname -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f4bd3963-40da-47c2-8bbb-8bddffe84aa1n%40googlegroups.com.
[ansible-project] How to extract a specific value from input list ?
I have the following input list postgres_create_users: - {role: user1 , password: password1 } - {role: user2, password: password2} - {role: user3, password: password3} - {role: user4, password: password4} As part of J2 template file I need to extract the password of user4 - How this can be done ? insights.jdbc.password={{ postgres_create_users ??? }} Thank you -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/35226055-8674-4efd-84db-21f054a51cfdn%40googlegroups.com.
Re: [ansible-project] Define hostname for group based on index+1
First of all thank you - it works. But, can i spare the following definition ? *groups['web-server']* Basically in the begging of the playbook I'm defining the group under hosts - hosts: web-server ב-יום שישי, 15 באפריל 2022 בשעה 11:58:31 UTC+3, ra...@linuxia.de כתב/ה: > On 15/04/2022 09:18, dudu.c...@gmail.com wrote: > > Hi, > > > > I have X amount of server inside a defined group (For example - web > server) > > I want to loop the server a define there hostname based on index+1 > > > > For example, if the group have 3 server , so server one should be > "web-server1" , second , "web-server-2" etc. > > > > The below didnt do the trick - since it is looping the sequence for each > server > > - hosts: web-server > > remote_user: user > > become: yes > > tasks: > > - name: Set a hostname > > hostname: > > name: web-server-{{ item }} > > > > > > with_sequence: count=3 > > Using a loop is futile here, as you found out. But you can do that with a > bit Python: > > - name: Set a hostname > hostname: > name: "web-server-{{ groups['web-server'].index(inventory_hostname) }}" > > Regards > Racke > > > > > -- > > You received this message because you are subscribed to the Google > Groups "Ansible Project" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to ansible-proje...@googlegroups.com ansible-proje...@googlegroups.com>. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/4d7a9bb7-6403-4ac9-b77f-4212fafc5680n%40googlegroups.com > > < > https://groups.google.com/d/msgid/ansible-project/4d7a9bb7-6403-4ac9-b77f-4212fafc5680n%40googlegroups.com?utm_medium=email_source=footer > >. > > > -- > Automation expert - Ansible and friends > Linux administrator & Debian maintainer > Perl Dancer & conference hopper > > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fe43e1e3-ea11-4626-8855-2039a1b786a4n%40googlegroups.com.
[ansible-project] Define hostname for group based on index+1
Hi, I have X amount of server inside a defined group (For example - web server) I want to loop the server a define there hostname based on index+1 For example, if the group have 3 server , so server one should be "web-server1" , second , "web-server-2" etc. The below didnt do the trick - since it is looping the sequence for each server - hosts: web-server remote_user: user become: yes tasks: - name: Set a hostname hostname: name: web-server-{{ item }} with_sequence: count=3 -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4d7a9bb7-6403-4ac9-b77f-4212fafc5680n%40googlegroups.com.
[ansible-project] Adding if statement inside a task
Hi I have the following playbook. In the environment.yml file I have a parameter "tls=true" In the below task , In tghe URL I would put *https* if tls=true and *http* if false. - hosts: manager vars_files: - ./environment.yml tasks: - name: test - check connectivity to API get_url: url: http://{{ server.hostname }}.{{ domain }}:/api//{{ cluster_name }} dest: /tmp/ mode: 0777 force: yes url_username: "{{ username }}" url_password: "{{ password }}" validate_certs: no register: msg ignore_errors: true Thanks -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d87db8f5-2d22-4d65-8d16-efa6a3041012n%40googlegroups.com.
[ansible-project] with_items -- only part of the group in my inventory
Hi, I have a task based on shell command that need to run on local computer. As part of the command I need to add the IP address of part of the groups I have in my inventory file *Inventory file :* [server1] 130.1.1.1 130.1.1.2 [server2] 130.1.1.3 130.1.1.4 [server3] 130.1.1.5 130.1.1.6 I need to run the following command from local computer on the Ips that are part of the Server 2 + 3 groups Ssh-copy-id user@IP ; IP should be 130.1.1.3 , 130.1.1.4 , 130.1.1.5 , 130.1.1.6 *Playbook* - hosts: localhost gather_facts: no become: yes tasks: - name: Generate ssh key for root user shell: "ssh-copy-id user@{{ item }} run_once: True with_items: - server2 group - server3 group Thank you -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/dbee443f-4055-4d27-96ca-9f6e1e6aaf7en%40googlegroups.com.
[ansible-project] How to set hostname with running number
Hi, In my inventory file i have 3 server, I need to set the hostname including prefix1-3 web1 web2 web3 *Inventory fie:* [web] 192.168.0.47 192.168.0.48 192.168.0.49 *Playbook* - hosts: - web become: true any_errors_fatal: true tasks: - name: update hostname hostname: name : "web " -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2dd18239-c65d-4717-9d90-af4c2aba1a68n%40googlegroups.com.
[ansible-project] Upload var_files based on a value or ignore if not exist
- hosts: server1 vars_files: - main.yml - second.yml Hi, I have a a small playbook that is using variables based on a file. Main.yml the file will always exist while second.yml might exist. 1. Is it possible to configure the playbook to continue in case second.yml file does not existt? 2. If I will add to the main. yam the following value Additional_file: yes Can I configure the playbook to load second.yml only in case Additional_file value = yes Thanks -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c5f132d2-745e-454a-8a62-bea207121f23n%40googlegroups.com.
[ansible-project] ansible - J2 template
Ansible question I have a variable, let call it value1 and a J2 template. The J2 template includes the following line : LINE=” This string mut be included this string is optional= {{ value1}}” What I need to implement If value1 is defined with a string – let assume that the string is OK (Value1: OK) , the file should be LINE=” This string must be includedthis string is optional= OK” If value1 is not defined (empty Value1: ) –the file should be LINE=” This string must be included” So how the J2 should be configured? -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f9c56cbd-6356-4efd-b0d7-2e6abe9faf9dn%40googlegroups.com.
[ansible-project] How to ignore files that can not be found as part of vars_files
Hi, I need to upload 5 files as part of vars_files. There is a chance that one of the files is missing and in this case i want to ignore it - How can i do that. This is my solution for a single file , but how can i used it for 5 files vars: - optional_1_vars_file: "{{ lookup('first_found', '1.yml', errors='ignore') }}" tasks: - when: optional_1_vars_file is file include_vars: "{{ optional_1_vars_file }}" -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/48988f48-b607-4f8e-b36d-74efc634b7fcn%40googlegroups.com.
[ansible-project] How to extract specific value from register output
How to extract a specific value from register output: >From the below register output I’m trying to extract the * path *value with no luck, I have tried few options but still, I’m falling - debug: msg: "{{ file_name }}" - debug: msg: "{{ file_name.results.path }}" - debug: msg: "{{ file_name.path }}" File_name register output "msg": { "changed": false, "msg": "All items completed", "results": [ { "ansible_loop_var": "item", "changed": false, "checksum": "45823e35872e278fe781a182aa50abcd92d2df62", "dest": "/data/nifi-deployment/file_32.tar.gz", "diff": { "after": { "path": "/data/nifi-deployment/file_32.tar.gz" }, "before": { "path": "/data/nifi-deployment/file_32.tar.gz" } }, "failed": false, "gid": 0, "group": "root", "invocation": { "module_args": { "_diff_peek": null, "_original_basename": " file_32.tar.gz ", "access_time": null, "access_time_format": "%Y%m%d%H%M.%S", "attributes": null, "backup": null, "content": null, "delimiter": null, "dest": "/data/nifi-deployment", "directory_mode": null, "follow": true, "force": true, "group": null, "mode": null, "modification_time": null, "modification_time_format": "%Y%m%d%H%M.%S", "owner": null, "path": "/data/nifi-deployment/file_32.tar.gz", "recurse": false, "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "file", "unsafe_writes": null } }, "item": "/repo/file_32.tar.gz ", "mode": "0644", "owner": "root", * "path": "/data/nifi-deployment/file_32.tar.gz",* "secontext": "system_u:object_r:default_t:s0", "size": 4938, "state": "file", "uid": 0 } ] } } -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/bdbb05c9-e58f-410d-8181-868ab76a5b11n%40googlegroups.com.
[ansible-project] How can I use with_items twice in a single tasks?
How can I use with_items twice in a single tasks? For example , using line-in-file , I wish to update few parameters on a file that can be found on 2 locations - name: update file lineinfile: path: {{ item }} *<-- This should describe the files* regexp: "{{ item.from }}" line: "{{ item.replace_with }}" with_items: - { from: parameter1= , replace_with: parameter1=test1 } - { from: parameter1= , replace_with: parameter1=test2 } with_items: *-- > This should be for the path* - “/opt/file1” - “/opt/file2” -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/14ead263-3f7c-4e3a-825d-9882ed3aa777n%40googlegroups.com.
[ansible-project] line-in-file . line update from a list of values
Hi I’m using lineinfile to include new value inside a file *Original line * Kafka-list= kafka1:9092;kafka2:9092;kafka3:9092 I need to replace the value with parameters that are managed inside a configuration – I need to include all server hostname that are under kafka_server_details section The line format should be :;:; …… The list can include 1 or more servers *Configuration File : * kafka_server_details: - {ip: 1.1.1.1 , hostname: kafka1.cluster1.com } - {ip: 1.1.1.2 , hostname: kafka2.cluster1.com } - {ip: 1.1.1.3 , hostname: kafka3.cluster1.com } kafka_port: 9092 *Playbook * - name: Update flow.properties file lineinfile: path: /opt/flow.properties regexp: "{{ item.from }}" line: "{{ item.replace_with }}" with_items: - { from: lab=, replace_with: lab=1 } - { from: Kafka-list=, replace_with: "Kafka-list= {{ kafka_server_details.hostname }}:{{ kafka_port }} ; {{ kafka_server_details.hostname }}:{{ kafka_port }} ; {{ kafka_server_details.hostname }}:{{ kafka_port }} ; " } -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5160269d-f999-4aef-86e3-45fe73995f39n%40googlegroups.com.
Re: [ansible-project] Run task based on value in register
It looks that the item is not been searched in teh register - Maybe I need to implement a a regex search? if so how? On Thursday, November 12, 2020 at 2:34:00 PM UTC+2 brae...@gmail.com wrote: > On 11/12/20 1:12 PM, dudu.c...@gmail.com wrote: > > I have created a playbook that should run the following scenario – I’m > having a problem with the second tasks > > > > 1. Query the source Kafka for a topic list and save the output in > register > > > > 2. Run topics creation as a loop on destination kafka > > > > a. Topics list is taken from the input file > > > > b. The topic will be created only if the topic exists in the > source kafka > > > > > > > > Playbook tasks explanation – It seems that task 6 is been skipped > > > > Host: source Kafka > > > > 1. Task 1 : connect to source Kafka and get a list of topic à > update register > > > > 2. Task 2: print topic list – debug > > > > 3. Task 3 : Copy register output to a file > > > > Host: destination kafka > > > > 4. Task 4 : upload topic list from the file to a register > > > > 5. Task 5: print register > > > > 6. Task 6: create topic per input list, only if topic name exists > in register * If this can be done as a search > > in file it will be much better (will save task 4) > > > > > > > > /## Verification > > /- hosts: > > - kafka_source_master_server[0] > > become: true > > any_errors_fatal: true > > gather_facts: False > > vars: > > zookeeper_port: 2999 > > tasks: > > > > - name: list topic from source kafka > > command: > > argv: > > - kafka-topics > > - --list > > - --zookeeper > > - localhost > > - "{{ zookeeper_port }}" > > register: kafka_topic_list > > > > - name: Debug - print list of Topics > > debug: > > msg: "{{kafka_topic_list.stdout_lines}}" > > / > > > > > > /- name: write results to a file > > local_action: copy content={{ kafka_topic_list.stdout_lines }} > dest=/tmp/topic-list.txt > > > > - hosts: > > - bigdata_kafka_master[0] > > become: true > > any_errors_fatal: true > > gather_facts: False > > vars_files: > > - ./environment.yml > > - ./kafka_enviroment.yml > > vars: > > zookeeper_port: 2999 > > srm_bin_path: > /opt/cloudera/parcels/STREAMS_REPLICATION_MANAGER/bin/srm-control > > tasks: > > > > - name: Update register with topic list > > shell: cat /tmp/topic-list.txt > > register: topic_list > > delegate_to: localhost > > > > > > - name: print topics > > debug: > > msg: "{{ topic_list.stdout_lines }}" > > > > - name: Create duplication per topic > > command: > > argv: > > - "{{ srm_bin_path }}" > > - topics > > - --source > > - "{{ kafka_source }}" > > - --target > > - "{{ kafka_destination }}" > > - --add > > - "{{ item }}" > > with_items: "{{ kafka_topics_to_be_mirrored }}" > > when: '"{{ kafka_topics_to_be_mirrored }}" in topic_list' > > > > In a loop when is evaluated for *every* item, so I think that might solve > your problem: > > when: item in topic_list > > Regards > Racke > > > > > > > -- > > You received this message because you are subscribed to the Google > Groups "Ansible Project" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to > > ansible-proje...@googlegroups.com ansible-proje...@googlegroups.com>. > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/ansible-project/b4d981e0-8d1e-43ea-aa17-a7c35afd4d42n%40googlegroups.com > > < > https://groups.google.com/d/msgid/ansible-project/b4d981e0-8d1e-43ea-aa17-a7c35afd4d42n%40googlegroups.com?utm_medium=email_source=footer > >. > > > -- > Ecommerce and Linux consulting + Perl and web application programming. > Debian and Sympa administration. Provisioning with Ansible. > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c7de7fde-2b82-457f-bea3-f37bc710b06fn%40googlegroups.com.
[ansible-project] Run task based on value in register
I have created a playbook that should run the following scenario – I’m having a problem with the second tasks 1. Query the source Kafka for a topic list and save the output in register 2. Run topics creation as a loop on destination kafka a. Topics list is taken from the input file b. The topic will be created only if the topic exists in the source kafka Playbook tasks explanation – It seems that task 6 is been skipped Host: source Kafka 1. Task 1 : connect to source Kafka and get a list of topic à update register 2. Task 2: print topic list – debug 3. Task 3 : Copy register output to a file Host: destination kafka 4. Task 4 : upload topic list from the file to a register 5. Task 5: print register 6. Task 6: create topic per input list, only if topic name exists in register * If this can be done as a search in file it will be much better (will save task 4) *## Verification *- hosts: - kafka_source_master_server[0] become: true any_errors_fatal: true gather_facts: False vars: zookeeper_port: 2999 tasks: - name: list topic from source kafka command: argv: - kafka-topics - --list - --zookeeper - localhost - "{{ zookeeper_port }}" register: kafka_topic_list - name: Debug - print list of Topics debug: msg: "{{kafka_topic_list.stdout_lines}}" - name: write results to a file local_action: copy content={{ kafka_topic_list.stdout_lines }} dest=/tmp/topic-list.txt - hosts: - bigdata_kafka_master[0] become: true any_errors_fatal: true gather_facts: False vars_files: - ./environment.yml - ./kafka_enviroment.yml vars: zookeeper_port: 2999 srm_bin_path: /opt/cloudera/parcels/STREAMS_REPLICATION_MANAGER/bin/srm-control tasks: - name: Update register with topic list shell: cat /tmp/topic-list.txt register: topic_list delegate_to: localhost - name: print topics debug: msg: "{{ topic_list.stdout_lines }}" - name: Create duplication per topic command: argv: - "{{ srm_bin_path }}" - topics - --source - "{{ kafka_source }}" - --target - "{{ kafka_destination }}" - --add - "{{ item }}" with_items: "{{ kafka_topics_to_be_mirrored }}" when: '"{{ kafka_topics_to_be_mirrored }}" in topic_list' -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b4d981e0-8d1e-43ea-aa17-a7c35afd4d42n%40googlegroups.com.
[ansible-project] Force ansible to ask for username and password when running task on a server
My ansible server and playbook are running on a closed environment – So basically everything is been accessed by know ssh-keys and I don’t need to supply any user and password while running the playbooks. I need to create a new playbook that the first task requires to connect to a server that is not part of my environment (customer environment) – Since I cannot take the SSH key of the server, I need to force the task to ask for the username , password , and the root password (become = ture) this in order to connect the server – How can this be done as part of a task or playbook ? Thanks -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9a30c05b-a80f-4463-abcb-7addcd8df3can%40googlegroups.com.
[ansible-project] Reading partial string
Hi, I have a simple playbook that takes an IP address from the input file and update this IP including hostname under /etc/hosts. The problem is that in the input file the IP is written with subnet – 1.1.1.1/24 While I need only the IP 1.1.1.1 *Playbook :* - hosts: localhost become: true any_errors_fatal: true gather_facts: False vars_files: - /opt/ input-file.yml tasks: - name: Update server etc/host with response ip lineinfile: path: /etc/hosts line: "{{ lb_ext_ip }}hdfs" state: present backup: yes *Result in /etc/hosts* 1.1.1.1/24hdfs *Required results:* 1.1.1.1 hdfs -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/272a5ee9-5200-4390-98d9-1d51f469b051n%40googlegroups.com.