Re: [ansible-project] lineinfile using insertafter

2020-07-18 Thread S C Rigler
It would be a lot easier to accomplish this with the ini_file module
instead of lineinfile.  For example:

- ini_file:
path: /etc/yum.repos.d/zabbix.repo
section: zabbix-non-supported
option: proxy
value: http://proxy:8080

On Fri, Jul 17, 2020 at 3:22 PM 'Chris Bidwell - NOAA Federal' via Ansible
Project  wrote:

> Hey all,
>
> Trying to insert a line to multiple instances in the same file.
>
> I tried insertafter but that only put in one spot.  Here's the code:
>
> - name: add proxy to zabbix.repo if needed
>   lineinfile:
> path: /etc/yum.repos.d/zabbix.repo
> state: present
> insertafter: '\[zabbix*'
> line: 'proxy=http://proxy:8080'
>   when:
> - ansible_default_ipv4.address is match('192\.168\.226\.') or
>   ansible_default_ipv4.address is match('10\.172\.226\.')
>
> Here's the result:
>
> [zabbix]
> name=Zabbix Official Repository - $basearch
> baseurl=https://repo.zabbix.com/zabbix/4.4/rhel/8/$basearch/
> enabled=1
> gpgcheck=1
> gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
>
> [zabbix-non-supported]
> *proxy=http://proxy:8080    *
>
>
> name=Zabbix Official Repository non-supported - $basearch
> baseurl=https://repo.zabbix.com/non-supported/rhel/8/$basearch/
> enabled=1
> gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
> gpgcheck=1
>
> I would have thought my insertafter regexp would match both of those
> [zabbix] and [zabbix-non-supported] but it doesn't.
>
> --
> 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/CAHKi8Cg_J_ybBhRZ8S0VVX0c6SqB-W2vz6nVNo9nFKNuia%2Bb-A%40mail.gmail.com
> 
> .
>

-- 
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/CAFbiokdpBPE-oQNQ75q7c4rd8x_bAK12ZYpstVkKfvHhimBAYg%40mail.gmail.com.


Re: [ansible-project] lineinfile using insertafter

2020-07-17 Thread Stefan Hornburg (Racke)
On 7/17/20 10:21 PM, 'Chris Bidwell - NOAA Federal' via Ansible Project wrote:
> Hey all,
> 
> Trying to insert a line to multiple instances in the same file.  
> 
> I tried insertafter but that only put in one spot.  Here's the code:
> 
>     - name: add proxy to zabbix.repo if needed
>       lineinfile:
>         path: /etc/yum.repos.d/zabbix.repo
>         state: present
>         insertafter: '\[zabbix*'
>         line: 'proxy=http://proxy:8080'
>       when:
>         - ansible_default_ipv4.address is match('192\.168\.226\.') or
>           ansible_default_ipv4.address is match('10\.172\.226\.')
> 
> Here's the result:
> 
> [zabbix]
> name=Zabbix Official Repository - $basearch
> baseurl=https://repo.zabbix.com/zabbix/4.4/rhel/8/$basearch/
> enabled=1
> gpgcheck=1
> gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
> 
> [zabbix-non-supported]
> *proxy=http://proxy:8080   *                                                  
>                                          
>                                                
> name=Zabbix Official Repository non-supported - $basearch
> baseurl=https://repo.zabbix.com/non-supported/rhel/8/$basearch/
> enabled=1
> gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
> gpgcheck=1
> 
> I would have thought my insertafter regexp would match both of those [zabbix] 
> and [zabbix-non-supported] but it doesn't.

No, lineinfile replaces one line. But why don't you set the proxy variable 
globally for yum / your system?

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-project+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAHKi8Cg_J_ybBhRZ8S0VVX0c6SqB-W2vz6nVNo9nFKNuia%2Bb-A%40mail.gmail.com
> .


-- 
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/20b9be73-44b4-4a33-8258-d00b200e1f47%40linuxia.de.


signature.asc
Description: OpenPGP digital signature


[ansible-project] lineinfile using insertafter

2020-07-17 Thread 'Chris Bidwell - NOAA Federal' via Ansible Project
Hey all,

Trying to insert a line to multiple instances in the same file.

I tried insertafter but that only put in one spot.  Here's the code:

- name: add proxy to zabbix.repo if needed
  lineinfile:
path: /etc/yum.repos.d/zabbix.repo
state: present
insertafter: '\[zabbix*'
line: 'proxy=http://proxy:8080'
  when:
- ansible_default_ipv4.address is match('192\.168\.226\.') or
  ansible_default_ipv4.address is match('10\.172\.226\.')

Here's the result:

[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://repo.zabbix.com/zabbix/4.4/rhel/8/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-non-supported]
*proxy=http://proxy:8080    *


name=Zabbix Official Repository non-supported - $basearch
baseurl=https://repo.zabbix.com/non-supported/rhel/8/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1

I would have thought my insertafter regexp would match both of those
[zabbix] and [zabbix-non-supported] but it doesn't.

-- 
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/CAHKi8Cg_J_ybBhRZ8S0VVX0c6SqB-W2vz6nVNo9nFKNuia%2Bb-A%40mail.gmail.com.