[ansible-project] Re: Multi-tenant best practices for Ansible Tower

2019-05-28 Thread Adam E
Check out 
https://docs.ansible.com/ansible-tower/latest/html/userguide/organizations.html 
to 
see if it meets your needs.

Your post should be posted to the awx project forum 
https://groups.google.com/forum/#!forum/awx-project

On Monday, May 27, 2019 at 10:49:19 AM UTC-7, dimple rohara wrote:
>
> Hi,
>
> I am a Devops engineer with a reputed bank in Canada. I want to know the 
> best practices that should be followed while designing multi-tenant 
> architecture in Ansible Tower. Please help as I am not able to find 
> something useful over internet about this.
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/91b0a527-834e-42a7-88d9-6994996841af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Running ansible tasks in background and disown

2019-05-15 Thread Adam E

not sure if you would get different results, but maybe try nohup instead of 
disown.  ie.
- name: execute sar iostat scripts shell: nohup top -bd $MON_INTERVAL > 
$GLUSTER_PROFILER_RESULTS/top_proc.$HOSTNAME.txt &

Another option could be to use the "at" module to schedule a task to start 
immediately. ie..

- name: Schedule a command to execute in 0 minutes as root. 
  at: 
command: top -bd $MON_INTERVAL > 
$GLUSTER_PROFILER_RESULTS/top_proc.$HOSTNAME.txt 
count: 0 
units: minutes


On Tuesday, May 14, 2019 at 11:23:42 PM UTC-7, Kaustav Majumder wrote:
>
> Hi all, i am trying to top , sar , iostats in the backgound via ansible on 
> remote hosts and collect stats redirecting outpu to a log file while I run 
> other tasks from my local machine. I have tried - name: collect hypervisor 
> stats hosts: all tasks: - name: execute sar iostat scripts shell: top -bd 
> $MON_INTERVAL > $GLUSTER_PROFILER_RESULTS/top_proc.$HOSTNAME.txt & disown 
> but it stops by itself. I want to kill the tasks after sometime manually. 
> Is there any way
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/da859989-caa7-491e-93ea-23eb64f2bf06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] ansible_python_interpreter facts.d

2019-05-13 Thread Adam E
Hi there.

On a few old/legacy systems I have installed python 2.6 in a nondefault 
location whereas the "default" (path) is an older version such as 2.4.
In some cases I have legacy apps that may need the old version and I don't 
want to affect their environment.

Setting ansible_python_interpreter to the python26 binary works well, 
however I also have a bunch of facts.d scripts which use python, 
unfortunately these pickup the 2.4 version.   I was just wondering if there 
is a built in solution to handle this?  

The current solution I came up with was to use the environment.PATH setting 
in the ansible playbook to add a path which contains the 26 python binary.  
This works with a caveat, however facts appear to be gathered before the 
PATH is set, so i need to regather facts after I set the environment.

The other solution I was thinking of is just maintaining a symbolic link to 
the correct python version which then I would hard code in the shebang for 
the python facts scripts.

Just wondering if anyone has a better solution or perhaps this might be a 
good enhancement request.   Perhaps the ansible setup module could detect 
that the fact script is python and call it with 
the ansible_python_interpreter if it's set?

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c4586a39-4923-48aa-a53a-7184899eaab8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Pass a variable in "vars_file" to "with_items" from command prompt as part of "extra-vars"

2019-05-10 Thread Adam E
Not sure if it meets your needs, but why not do something like this:

- hosts: localhost
>   vars:
> docker_configs:
>   tomcat: { cName: 'tomcatImg', iName: 'tomcat:latest', iPort: , 
> volumes: '/temp' }
>   nginx: { cName: 'nginxImg', iName: 'nginx:latest', iPort: 8001, 
> volumes: '/data' }
>   tasks:
> - name: configure images
>   debug:
> msg: "going to configure {{ docker_config }} on {{ 
> ansible_hostname }}"
>   vars:
> docker_config: "{{ docker_configs[item] }}"
>   loop: "{{ docker_images }}"



Then you can pass list of images to configure on the command line or add to 
your host_vars.

ansible-playbook -e "docker_images=['nginx','tomcat']" testa.yml


On Thursday, May 9, 2019 at 11:04:45 PM UTC-7, Anuradha Gangu wrote:
>
> My main objective is, I want to create a playbook with one task which will 
> take list of docker images and list of hosts and then run one image on one 
> host respectively or run list of images on one of host list supplied.
> To make it clear on understanding consider below declaration
>
> hostImageList:
>- { hostList: { host: 'abc' }, imageList: { cName: 'tomcatNewImg', iName: 
> 'tomcat:latest', iPort: , volumes: '/temp' } }
>- { hostList: { host: 'xyz'}, imageList: { cName: 'nginxNewImg', iName: 
> 'nginx:latest', iPort: , volumes: '/data' } }
>
> abc and xyz are defined in my ansible/hosts file. Now tomcat image should 
> be run on abc host and
> nginx image on xyz.
>
> There might be a need where I might need both tomcat , nginx on abc .
>
> So, my playbook should be able to achieve this.
>
> I was having challenges to loop hosts and image list together in a task in 
> playbook.
>
> *So to achieve this, I am trying as below -*
>
> Wrote a playbook with a task which will take list of docker images to be 
> run and run the images on the host name supplied through command prompt. I 
> am using docker-container module of ansible for this.
>
> I am have file img_vars.yml in which I have defined my list of items to be 
> used in my playbook.
> I need to pass the variable defined in this yml to playbook from commmand 
> prompt to with_items
> ANSIBLE VERSION
>
> Ansible: 2.7.10 on RHEL 7.x
>  STEPS TO REPRODUCE
>
> Created below yml files:
>
> img_vars.yml
>
> ---
>  imageList:
>- { cName: 'tomcatImg', iName: 'tomcat:latest', iPort: , volumes: 
> '/temp' }
>
>  imageNginxList:
>- { cName: 'nginxImg', iName: 'nginx:latest', iPort: 8001, volumes: 
> '/data' }
>
>  hostImageList:
>- { hostList: { host: 'abc', user: 'tcs', pwd: 'tcs@12345' }, imageList: { 
> cName: 'tomcatNewImg', iName: 'tomcat:latest', iPort: , volumes: '/temp' 
> } }
>- { hostList: { host: 'xyz', user: 'tcs', pwd: 'tcs@12345' }, imageList: { 
> cName: 'nginxNewImg', iName: 'nginx:latest', iPort: , volumes: '/data' } }
>
> my main playbook yml file
>
> ---
> - name: Ansible Looping Expirement
>   hosts: "{{ gethostname  }}"
>   gather_facts: true
>   become: yes
>   become_method: sudo
>   vars_files:
> - img_vars.yml
>   tasks:
>- name: Installing docker images using loops in Ansible
>  docker_container:
> name: "{{ item.cName }}"
> image: "{{ item.iName }}"
> state: started
> #exposed_ports:
> #   - "{{ item.iPort }}"
> volumes: "{{ item.volumes }}"
>  with_items:  "{{ ' getwithlist' }}"
>
>
> Running my playbook with below command
> ansible-playbook --ask-become-pass main.yml --extra-vars "gethostname=abc 
> getwithlist=imageList"
>
> Here I am trying to pass "imageList" which is defined in img_vars.yml from 
> command prompt through getwithlist variable.
> EXPECTED RESULTS
>
> Playbook executed successfully and run docker image "tomcat" on host 
> supplied through gethostname .
>
> getwithlist in with_items should be replaced by imageList and the value of 
> imageList in img_vars.yml should be picked up in with_items. So if this 
> variable replacement happens correctly, tomcat image will be running on 
> remote host.
>
> When I want to install another image on another host, i will run playbooks 
> with changed parameters as below :
> ansible-playbook --ask-become-pass main.yml --extra-vars "gethostname=xyz 
> getwithlist=imageNginxList"
> ACTUAL RESULTS
>
> Am getting below error
>
> "msg": "The task includes an option with an undefined variable. The error 
> was: 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 
> 'iName'\n\nThe error appears to have been in 
> '/u01/HomeDir/e166110/ansible_poc/loops/dynamic_loop_docker.yml': line 10, 
> column 6, but may\nbe elsewhere in the file depending on the exact syntax 
> problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: 
> Installing docker images using loops in Ansible\n ^ here\n"
>
> Am doing a mistake but not sure where am doing. Can someone guide me 
> please ?
> Is my main objective which I described in beginning is achievable ?
>

-- 
You received this message 

Re: [ansible-project] $PATH with shell is different to manual ssh

2019-05-09 Thread Adam E
I deal with a lot of legacy systems that don't always have great path 
defaults for working with Ansible.   I ended up putting the following at 
the top of my main playbook to add some common locations to the path if 
they were not present.  Might help in your case if you can't easily modify 
the standard profiles.   it seems to work well.

  vars:
> paths_extras: ['/usr/local/sbin', '/usr/local/bin', '/sbin', '/bin', 
> '/usr/sbin', '/usr/bin']
>   environment:
>   PATH: |-
>   {% set new_path = ansible_env.PATH.split( ':' )  %}
>   {% for path in paths_extras %}
> {% if path not in new_path %}
>   {{ new_path.append(path) }}
> {% endif %}
>   {% endfor %}
>   {{ new_path | join( ':' ) }}


On Wednesday, May 8, 2019 at 5:25:08 PM UTC-7, Matthew Davis wrote:
>
> Ah yes, I see that bit in .bashrc.
>
> Is there any way to open an interactive shell, but source .bashrc as a 
> non-interactive shell?
> I just want to be able to emulate the environment Ansible runs in.
>
> I tried 
>
> PATH="" PS1="" . /home/centos/.bashrc ; echo $PATH
>
> But that didn't work
>
> Thanks,
> Matt
>
>
>
> On Wednesday, May 8, 2019 at 11:38:47 PM UTC+10, Matt Martz wrote:
>>
>> I think the key terms here are likely interactive vs non-interactive 
>> shells.
>>
>> A bashrc or bash profile may have lines that look like:
>>
>> # If not running interactively, don't do anything
>> [ -z "$PS1" ] && return
>>
>> or 
>>
>> # If not running interactively, don't do anything
>> case $- in
>> *i*) ;;
>>   *) return;;
>> esac
>>
>> This prevents those files from running in a non-interactive shell, and 
>> those files, from a global perspective, source other files including your 
>> personal rc or profile files.
>>
>> As such, since ansible uses non-interactive shells, you will often have a 
>> different shell environment when interactively logged in.
>>
>>
>>
>> On Tue, May 7, 2019 at 7:14 PM Matthew Davis  wrote:
>>
>>> Hi,
>>>
>>> I have been redirected from Github issue 56044 
>>> .
>>>
>>> I am finding that commands which work when run manually fail when run 
>>> with a shell task, because the $PATH is different, so binaries such as ip 
>>> and modinfo cannot be found.
>>>
>>> Bcoca said:
>>>
>>> > In any case this is due to Ansible doing a batch login, which does not 
>>> source the same files as a live login, this depends on your system's 
>>> configuration and can be changed by setting the PATH the same way for both 
>>> types of logins.
>>>
>>> What does that mean?
>>> When I search online for batch logins, I get a whole bunch of irrelevant 
>>> results about Windows Batch scripts.
>>> Is this the batch you see with `man batch`?
>>> How can I make an Ansible shell task execute with the same $PATH as when 
>>> I ssh in manually?
>>>
>>> I am only having this problem on a Centos target, not Ubuntu. (Perhaps 
>>> the PATH is modified for Ubuntu too, but it is not impacting me because 
>>> Ansible's shell task can still find the binaries I need.)
>>> I am already telling Ansible to use bash not sh.
>>>
>>> Detail
>>>
>>> *Steps to reproduce*
>>>
>>> I am trying to use shell to run the modinfo binary, and also the ip 
>>> binary.
>>> I can run the command I want manually by ssh-ing into the machine.
>>> But when I do it with Ansible, shell says "command not found", because 
>>> the $PATH is different between SSH and Ansible shell.
>>>
>>> This happens with Ansible version 2.5 and 2.9.
>>>
>>> My target is Centos 7.6
>>>
>>> When I manually ssh in I see:
>>>
>>>
>>> [centos@dell03 ~]$ which modinfo
>>> /usr/sbin/modinfo
>>> [centos@dell03 ~]$ echo $PATH
>>> /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin
>>> [centos@dell03 ~]$ modinfo ext4 
>>>
>>> That last command prints out a lot of text, and returns 0.
>>>
>>> Then I try with ansible:
>>>
>>>
>>> ---
>>> - hosts: localhost
>>>   tasks:
>>>
>>> - name: check modinfo
>>>   shell: | echo $PATH which modinfo  modinfo 
>>> ext4  args:
>>>  executable: /bin/bash
>>>
>>>
>>> *Expected results:*
>>>
>>>
>>>- task should pass
>>>- stdout should be
>>>
>>> /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin
>>>  
>>>
>>>
>>> followed by a lot of text about the ext4 module
>>>
>>> i.e. shell can find the modinfo binary because the PATH is the same as 
>>> before.
>>>
>>>
>>>
>>>
>>> *Actual Result*fatal: [10.58.2.103]: FAILED! => {
>>> "changed": true,
>>> "cmd": "echo $PATH\nwhich modinfo\nmodinfo ext4 \n",
>>> "delta": "0:00:00.003893",
>>> "end": "2019-05-03 16:50:23.683406",
>>> "invocation": {
>>> "module_args": {
>>> "_raw_params": "echo $PATH\nwhich modinfo\nmodinfo ext4 \n",
>>> "_uses_shell": true,
>>> "argv": null,
>>> "chdir": null,
>>> "creates": null,
>>>   

Re: [ansible-project] multiline jinja2 lists returned as string?

2019-05-08 Thread Adam E
dang, could have sworn I tried that.   It works, thanks Matt, that's 
exactly what I was looking for!!  appreciate it.

On Wednesday, May 8, 2019 at 1:58:55 PM UTC-7, Matt Martz wrote:
>
> The root of the problem is a bit complicated, and rooted in the fact that 
> historically jinja2 could only return strings.  So we have code that 
> attempts to safely convert string representations of python datastructures 
> into actual python data structures.
>
> What appears to be your problem is a bunch of added whitespace caused by 
> the jinja2 templating.  The following seems to resolve the problem:
>
> users: >-
>   {%- set cusers = ['user1', 'user2'] -%}
>   {%- if ansible_distribution == "RedHat" -%}
>   {{ cusers.append('redhat_user') }}
>   {%- else -%}
>   {{ cusers.append('other_user') }}
>   {%- endif -%}
>   {{ cusers | list }}
>
> Notice the use of {%- and -%} which informs jinja2 to strip whitespace.  
> See http://jinja.pocoo.org/docs/dev/templates/
>
> > You can also strip whitespace in templates by hand. If you add a minus 
> sign (-) to the start or end of a block (e.g. a For tag), a comment, or a 
> variable expression, the whitespaces before or after that block will be 
> removed
>
> On Wed, May 8, 2019 at 3:43 PM Adam E > 
> wrote:
>
>> thanks for the reply, I had also thought of that solution and it's 
>> perfectly viable for my example (thanks).  however was looking for 
>> something that doesn't use multiple variables and avoids repetition.   My 
>> example was just a simple one, in some cases I have more complex jinja 
>> statements and the crux of what I was after was how to nicely do complex 
>> multiline jinja statements that use lists.
>>
>> On Wednesday, May 8, 2019 at 1:11:43 PM UTC-7, Kai Stian Olstad wrote:
>>>
>>> On 03.05.2019 22:15, Adam E wrote: 
>>> > Hi there, I have some logic that I want to apply when creating 
>>> assigning a 
>>> > list to a variable. 
>>> > 
>>> > See my sample playbook below, Ideally i'd like a nice clean way to 
>>> have a 
>>> > logic based list. the "users" approach works, however it's always 
>>> > interpreted as a string.  The only solution I can think of to fix this 
>>> one 
>>> > is to store it as a string and then split it later.  But I would like 
>>> to 
>>> > know if it's possible to return a list somehow.   Maybe there's a 
>>> different 
>>> > syntax that i'm not aware of.  Can anyone offer a better way to do 
>>> > something like below? 
>>> > 
>>> > - hosts: localhost 
>>> >connection: local 
>>> >vars: 
>>> >  # THIS does not work as it's interpreted as a string, would have 
>>> to 
>>> > split in a new var? 
>>> >  # is there anything I can do here to keep a similar syntax but 
>>> return a 
>>> > list? 
>>> >  users: >- 
>>> >{% set cusers = ['user1', 'user2'] %} 
>>> >{% if ansible_distribution == "RedHat" %} 
>>> >{{ cusers.append('redhat_user') }} 
>>> >{% else %} 
>>> >{{ cusers.append('other_user') }} 
>>> >{% endif %} 
>>> >{{ cusers | list }} 
>>> >  # THIS works but a little ugly with the newline 
>>> >  users2: "{% set cusers = ['user1', 'users2'] %}\ 
>>> >   {% if ansible_distribution == 'RedHat' %}\ 
>>> >   {{ cusers.append('redhat_user') }}\ 
>>> >   {% else %}\ 
>>> >   {{ cusers.append('other_user') }}\ 
>>> >   {% endif %}\ 
>>> >   {{ cusers }}" 
>>>
>>> Something like this should work 
>>>
>>>   vars: 
>>> cuser: ['user1', 'user2'] 
>>> users: "{{ cuser + ['redhat_user'] if ansible_distribution == 
>>> 'RedHat' else cuser + ['other_user'] }}" 
>>>
>>> -- 
>>> Kai Stian Olstad 
>>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to ansible...@googlegroups.com 
>> .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/14fa6ba6-67c2-4113-9d75-4c2312f0dc7b%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/14fa6ba6-67c2-4113-9d75-4c2312f0dc7b%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> -- 
> Matt Martz
> @sivel
> sivel.net
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d5c7af20-5a70-4cc7-b322-e65b4e1f46d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] multiline jinja2 lists returned as string?

2019-05-08 Thread Adam E
thanks for the reply, I had also thought of that solution and it's 
perfectly viable for my example (thanks).  however was looking for 
something that doesn't use multiple variables and avoids repetition.   My 
example was just a simple one, in some cases I have more complex jinja 
statements and the crux of what I was after was how to nicely do complex 
multiline jinja statements that use lists.

On Wednesday, May 8, 2019 at 1:11:43 PM UTC-7, Kai Stian Olstad wrote:
>
> On 03.05.2019 22:15, Adam E wrote: 
> > Hi there, I have some logic that I want to apply when creating assigning 
> a 
> > list to a variable. 
> > 
> > See my sample playbook below, Ideally i'd like a nice clean way to have 
> a 
> > logic based list. the "users" approach works, however it's always 
> > interpreted as a string.  The only solution I can think of to fix this 
> one 
> > is to store it as a string and then split it later.  But I would like to 
> > know if it's possible to return a list somehow.   Maybe there's a 
> different 
> > syntax that i'm not aware of.  Can anyone offer a better way to do 
> > something like below? 
> > 
> > - hosts: localhost 
> >connection: local 
> >vars: 
> >  # THIS does not work as it's interpreted as a string, would have to 
> > split in a new var? 
> >  # is there anything I can do here to keep a similar syntax but 
> return a 
> > list? 
> >  users: >- 
> >{% set cusers = ['user1', 'user2'] %} 
> >{% if ansible_distribution == "RedHat" %} 
> >{{ cusers.append('redhat_user') }} 
> >{% else %} 
> >{{ cusers.append('other_user') }} 
> >{% endif %} 
> >{{ cusers | list }} 
> >  # THIS works but a little ugly with the newline 
> >  users2: "{% set cusers = ['user1', 'users2'] %}\ 
> >   {% if ansible_distribution == 'RedHat' %}\ 
> >   {{ cusers.append('redhat_user') }}\ 
> >   {% else %}\ 
> >   {{ cusers.append('other_user') }}\ 
> >   {% endif %}\ 
> >   {{ cusers }}" 
>
> Something like this should work 
>
>   vars: 
> cuser: ['user1', 'user2'] 
> users: "{{ cuser + ['redhat_user'] if ansible_distribution == 'RedHat' 
> else cuser + ['other_user'] }}" 
>
> -- 
> Kai Stian Olstad 
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/14fa6ba6-67c2-4113-9d75-4c2312f0dc7b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] multiline jinja2 lists returned as string?

2019-05-03 Thread Adam E
Hi there, I have some logic that I want to apply when creating assigning a 
list to a variable.

See my sample playbook below, Ideally i'd like a nice clean way to have a 
logic based list. the "users" approach works, however it's always 
interpreted as a string.  The only solution I can think of to fix this one 
is to store it as a string and then split it later.  But I would like to 
know if it's possible to return a list somehow.   Maybe there's a different 
syntax that i'm not aware of.  Can anyone offer a better way to do 
something like below?

- hosts: localhost
  connection: local
  vars:
# THIS does not work as it's interpreted as a string, would have to 
split in a new var? 
# is there anything I can do here to keep a similar syntax but return a 
list?
users: >-
  {% set cusers = ['user1', 'user2'] %}
  {% if ansible_distribution == "RedHat" %}
  {{ cusers.append('redhat_user') }}
  {% else %}
  {{ cusers.append('other_user') }}
  {% endif %}
  {{ cusers | list }}
# THIS works but a little ugly with the newline
users2: "{% set cusers = ['user1', 'users2'] %}\
 {% if ansible_distribution == 'RedHat' %}\
 {{ cusers.append('redhat_user') }}\
 {% else %}\
 {{ cusers.append('other_user') }}\
 {% endif %}\
 {{ cusers }}"

  tasks:

 - debug:
 msg: "user: {{ item  }}"
   loop: "{{ users2 }}"

 

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/43910e1c-fa03-4bde-8a6d-ff995921238f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: Ansible how to subtract two variables in a playbook?

2019-04-30 Thread Adam E
Yeah, you can register the output of a shell command as a fact, below is 
simple example.  Matts reply looks much nicer though, i would use his so 
you are not dependent on shell commands.

from the man page of date:

>-r, --reference=FILE
>   display the last modification time of FILE


working example (replace filenametocheck with your actual filename)

>
> - hosts: localhost
>   connection: local
>   tasks:
> - shell: "echo $((($(date +%s) - $(date +%s -r 'filenametocheck')) / 
> 86400))"
>   register: file_check
> - set_fact:
> file_days: "{{ file_check.stdout |int }}"
> - debug:
> msg: "file is {{ file_days }} days old"



On Tuesday, April 30, 2019 at 7:47:04 PM UTC-7, Andy Magana wrote:
>
> So I really have been racking my melon on this  so your saying I can echo 
> with the shell module what is the -r any way ?
>
>
>
> On Tue, Apr 30, 2019 at 12:42 PM Adam E > 
> wrote:
>
>> You could run a "shell" command and register the output to a variable 
>> using a command something like the following:
>>
>> echo $((($(date +%s) - $(date +%s -r "$filename")) / 86400))
>>
>>
>> Alternatively, you could develop a action_plugin 
>> <https://docs.ansible.com/ansible/latest/plugins/action.html> that could 
>> accept the filename as a parameter and perform the logic in python by first 
>> calling the stat 
>> <https://docs.ansible.com/ansible/latest/modules/stat_module.html> 
>> module on the file as it also returns the last modification time of the 
>> file via mtime.
>>
>> On Monday, April 29, 2019 at 2:43:07 PM UTC-7, Andy Magana wrote:
>>>
>>> So I created a simple bash script to compare dates of the current date 
>>> and last date of a directory that was last modified.
>>>
>>> What I am looking for is something done in Ansible that can take the 
>>> converted date string of two variables and subtract the difference.
>>>
>>> We have these DAT MacAfee files, I just don’t like the bash script I 
>>> created and looking for something that can be done with a yaml playbook. 
>>>
>>> So here is my script: 
>>>
>>>
>>> #!/bin/bash
>>> # TO PRINT THE NUMBER OF DAYS SINCE LAST AV UPDATE
>>> past_date=$(du -h --time testdate | grep -Eo 
>>> '[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}')
>>>
>>>
>>> # Perform a subtraction of past_date string
>>> # from today's string divided by seconds times 12 hour days  
>>> diff=$((($(date +%s)-$(date +%s --date "$past_date"))/(3600*24)))
>>> echo It has been $diff days since the last AV DAT update
>>>
>>>
>>>
>>> Thanks in advance. 
>>>
>>> Andy Magana
>>>
>>> Oklahoma, City OK
>>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to ansible...@googlegroups.com 
>> .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/577a669c-0e52-4716-9cbf-cabd07d942ac%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/577a669c-0e52-4716-9cbf-cabd07d942ac%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1b0f7e60-4b49-4df1-9dad-493826f5cda8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Ansible how to subtract two variables in a playbook?

2019-04-30 Thread Adam E
You could run a "shell" command and register the output to a variable using 
a command something like the following:

echo $((($(date +%s) - $(date +%s -r "$filename")) / 86400))


Alternatively, you could develop a action_plugin 
 that could 
accept the filename as a parameter and perform the logic in python by first 
calling the stat 
 module 
on the file as it also returns the last modification time of the file via 
mtime.

On Monday, April 29, 2019 at 2:43:07 PM UTC-7, Andy Magana wrote:
>
> So I created a simple bash script to compare dates of the current date and 
> last date of a directory that was last modified.
>
> What I am looking for is something done in Ansible that can take the 
> converted date string of two variables and subtract the difference.
>
> We have these DAT MacAfee files, I just don’t like the bash script I 
> created and looking for something that can be done with a yaml playbook. 
>
> So here is my script: 
>
>
> #!/bin/bash
> # TO PRINT THE NUMBER OF DAYS SINCE LAST AV UPDATE
> past_date=$(du -h --time testdate | grep -Eo 
> '[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}')
>
>
> # Perform a subtraction of past_date string
> # from today's string divided by seconds times 12 hour days  
> diff=$((($(date +%s)-$(date +%s --date "$past_date"))/(3600*24)))
> echo It has been $diff days since the last AV DAT update
>
>
>
> Thanks in advance. 
>
> Andy Magana
>
> Oklahoma, City OK
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/577a669c-0e52-4716-9cbf-cabd07d942ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: How to mask connection string Passwords while connecting through DB using sqlplus ansible

2019-04-30 Thread Adam E
you could also look at using oracle wallet if you don't want to use 
environment variables for some reason.
https://docs.oracle.com/cd/B19306_01/network.102/b14266/cnctslsh.htm#g1033548


On Monday, April 29, 2019 at 4:04:37 PM UTC-7, Raj wrote:
>
> I am running into an issue where ansible is spitting up password, which 
> is  a security breach as these logs will automatically uploads to developer 
> shared location for review. How can I mask the passwords in spitting up 
> here. I need to use stdout_lines whether we run the job in clean state or 
> not, so I cant take out that from list. 
>
>   - name: Disabling Queue 
> shell: source ~/.bash_profile && sqlplus -S '{{ admin }}/{{ password 
> }}@{{ TNS_NAME }}' @"disable.sql"
> register: disable_queue
> delegate_to: localhost
> args:
>   chdir: roles/db-deploy/files/
> tags: Jobs
>
>
>   - debug: var=disable_jobqueue.stdout_lines
> delegate_to: localhost
> tags:Jobs
>
>
>
>
> TASK [db-deploy : Disabling Job Queue] 
> 21:46:20 [buildNode1] fatal: [Host1 -> localhost]: FAILED! => {"changed": 
> true, "cmd": "source ~/.bash_profile && sqlplus -S 
> 'userName/visiblePassword(DESCRIPTION = 
> (CONNECT_TIMEOUT=5)(RETRY_COUNT=0)(LOAD_BALANCE = off)(FAILOVER = 
> on)(ADDRESS_LIST=(ADDRESS = (PROTOCOL = TCP)(HOST = Host1)(PORT = 
> 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = Host1)(PORT = 1521)))(CONNECT_DATA 
> = (SERVICE_NAME = serviceName1)))' @\"disable.sql\"", "delta": 
> "0:00:00.412873", "end": "2019-04-25 02:46:20.036544", "msg": "non-zero 
> return code", "rc": 127, "start": "2019-04-25 02:46:19.623671", "stderr": 
> "/bin/sh: 
> sqlplus: command not found", "stderr_lines": ["/bin/sh: sqlplus: command 
> not found"], "stdout": "", "stdout_lines": []}
> 21:46:20 [buildNode1] fatal: [Host2 -> localhost]: FAILED! => {"changed": 
> true, "cmd": "source ~/.bash_profile && sqlplus -S 
> 'userName/visiblePassword(DESCRIPTION = 
> (CONNECT_TIMEOUT=5)(RETRY_COUNT=0)(LOAD_BALANCE = off)(FAILOVER = 
> on)(ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = Host2)(PORT = 
> 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = Host2)(PORT = 1521)))(CONNECT_DATA 
> = (SERVICE_NAME = serviceName2)))' @\"disable.sql\"", "delta": 
> "0:00:00.419597", "end": "2019-04-25 02:46:20.041097", "msg": "non-zero 
> return code", "rc": 127, "start": "2019-04-25 02:46:19.621500", "stderr": 
> "/bin/sh: 
> sqlplus: command not found", "stderr_lines": ["/bin/sh: sqlplus: command 
> not found"], "stdout": "", "stdout_lines": []}
> 21:46:20 [buildNode1] fatal: [Host3 -> localhost]: FAILED! => {"changed": 
> true, "cmd": "source ~/.bash_profile && sqlplus -S 
> 'userName/visiblePassword(DESCRIPTION = 
> (CONNECT_TIMEOUT=5)(RETRY_COUNT=0)(LOAD_BALANCE = off)(FAILOVER = 
> on)(ADDRESS_LIST=(ADDRESS = (PROTOCOL = TCP)(HOST = Host3)(PORT = 
> 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = Host3)(PORT = 1521)))(CONNECT_DATA 
> = (SERVICE_NAME = serviceName3)))' @\"disable.sql\"", "delta": 
> "0:00:00.419941", "end": "2019-04-25 02:46:20.054755", "msg": "non-zero 
> return code", "rc": 127, "start": "2019-04-25 02:46:19.634814", "stderr": 
> "/bin/sh: 
> sqlplus: command not found", "stderr_lines": ["/bin/sh: sqlplus: command 
> not found"], "stdout": "", "stdout_lines": []}
>
>
> Thanks and Regards
> Raj
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f332f738-0e58-411a-8590-853cdc217fe6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Run custom code before first task in playbook

2019-04-16 Thread Adam E
I do something similar, I just use the assert module to check a fact that I 
know should be set to a predefined value.

  - name: "linux : global assertions"
assert:
  that:
- "group_ld_all_000_global_defaults == 'loaded'"
  fail_msg: 'environment issue, please double check, this is most 
likely a issue with fact cache expiring'


On Monday, April 15, 2019 at 10:25:21 PM UTC-7, Pavel Martynov wrote:
>
> Hi!
>
> I use json facts caching and sometimes this files expires (last modified 
> time > than configured fact_caching_timeout).
> This is a rare problem, but if it arises - I have non-obvious errors in 
> stdout after running my playbook (like "ansible_fqdn is not defined in 
> host_vars", etc).
>
> My idea: run some custom assertion code, that should check all cache files 
> for expiration and stop further playbook run if there are some expired 
> cache files with a good understandable message.
> How can I embed my custom check code in playbook? Maybe I should write 
> some sort of ansible plugin?
>
> 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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/73107fb4-a615-4e95-b1f3-4a5ffe061a6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] list containing any item of another list

2019-04-03 Thread Adam E
Hi, wondering if there is any cleaner way to see if two lists have 1 or 
more intersecting values?

the following works for me

# returns true
> {{ ['value1', 'value2'] | intersect(['value1', 'value2']) | length > 0 }}
> # returns false
> {{ ['value3', 'value4'] | intersect(['value1', 'value2']) | length > 0 }}


just wondering if there is a cleaner looking solution that I am not aware 
of as I am using it frequently.  
something like would be handy. 

> {{ ['value1', 'value2].any(['value1', 'value2']) }}

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ac91665d-1ad3-4099-84df-e6b5513e16b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: Importing user variables from multiple variable sources

2019-03-21 Thread Adam E
another alternative if you don't want to use an external plugin is to 
predefine your variable names and then combine them..

ie...

> users_global
>
users_group 

users_host (variable you set in host_vars)


and then use the "combine 
"
 
filter to combine them together . 
ie..

> users_global | combine(users_group, recursive=True) | combine(users_host, 
> recursive=True)



I agree though, I am also coming from puppet and miss hiera.   I may still 
consider going back to using it as there appears to be support 
 for it, 
but it would be nice to be fully integrated

The strategy I ended up going with for the similar problem you have is
1. I created a "users" hash in vars/ which contains all users that can be 
managed
2. then in my host & group_vars I populate a list such as 
"linux_users_global" or linux_users_unique_name which contains the list of 
users that should be managed either globally, group or at the host level
3. then in my playbook I merge all the variables that match the pattern 
"linux_users.*" . (see this link 
)
4. then I loop through that merged list and manage those users

for me, the above solution works quite well.


On Thursday, March 21, 2019 at 12:07:09 PM UTC-7, Suhail Choudhury wrote:
>
> Hi. 
>
> Thanks for reply Kai. 
>
> Default Ansible cannot solve this problem, which I find very odd as it 
> was a common issue that is very elegantly addressed in Pupept using 
> Hiera. 
>
> However a solution has been found! 
>
> Have a look at: 
>
>
> http://leapfrogonline.io/articles/2017-02-22-explicit-merging-of-ansible-variables/
>  
> https://github.com/leapfrogonline/ansible-merge-vars 
>
> They have solved exactly this issue and I'm testing their plugin and 
> so far so good. Certainly not as elegant as Puppet/Hiera but it's a 
> working solution. 
>
> Regards, 
> Suhail. 
>
> On Thu, 21 Mar 2019 at 18:49, Kai Stian Olstad 
> > wrote: 
> > 
> > On 21.03.2019 12:58, Suhail Choudhury wrote: 
> > > Thanks for your earlier reply Adam. 
> > > 
> > > So how can I combine variables for a list of "users" defined like so: 
> > > 
> > > *group_vars/all* 
> > > 
> > > users: 
> > >- name: alice 
> > >  comment: Alice 
> > > 
> > > *group_vars/group1* 
> > > 
> > > users: 
> > >- name: bob 
> > >  comment: Bob 
> > > 
> > > *host_vars/host1* 
> > > 
> > > users: 
> > >- name: charlie 
> > >  comment: Charlie 
> > > 
> > > How can all these variables be combined using "loop" or "with_items"? 
> > 
> > You can't, they will be overwritten in the order listed here 
> > 
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable
>  
> > 
> > > What if there are duplicates? 
> > 
> > They are duplicates since all are call users and will be overwritten. 
> > 
> > 
> > > Can the "host_vars/host1" variables override and take precedence over 
> the 
> > > "group_vars/all" variables? 
> > 
> > It does. 
> > 
> > 
> > -- 
> > Kai Stian Olstad 
> > 
> > -- 
> > 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 post to this group, send email to ansible...@googlegroups.com 
> . 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/86213972-a12c-474a-0284-747eaa825cdd%40olstad.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b03d7f87-aef1-4d96-a1cd-77285441af13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: getting a variable indirectly

2019-03-14 Thread Adam E
i'm not sure if it would work on that old version, but couldn't you just 
copy the vars plugin 

 file 
into your local "lookup_plugins" directory?

On Tuesday, March 12, 2019 at 6:41:12 AM UTC-7, fusillator wrote:
>
> Hi Kai, in my current release 2.3.2.0 the hash vars is undefined as well 
> as the lookup plugin vars.
> What's more the hostvars dictionary collects only the inventories 
> variables (e.g. those defined in the files {host,group}_var/*) 
> Whereas if the variables related to a role (e.g. those defined in the 
> roles/*/{default,vars}/main.yml) are not gathered by the hash hostvars
> The only way I found to workaround the missing vars plugin is to build the 
> dictionary by myself, item by item
> Is there a way to retrieve the variable name string  given a variable? I'd 
> like to build the dictionary with a loop at least.
>
> thanks for your support
>
> Luca 
> 
>
> Il giorno martedì 12 marzo 2019 07:10:17 UTC+1, Kai Stian Olstad ha 
> scritto:
>>
>> On 12.03.2019 02:54, fusillator wrote: 
>> > #not yet working in ansible release 2.3.2 
>> > #  when: lookup('vars', item|basename, default=false) 
>> > #workaround see role variable confobjs in the playbook launcher 
>> >   when: confobjs[item|basename] is defined 
>> >   register: template_result 
>>
>> I'm not sure I understand what you are trying to achieve, but I think 
>> you are looking for this 
>>
>> hostvars[inventory_hostname][item|basename] is defined 
>>
>>
>> It's not recommended to use vars, but this also works 
>>
>> vars[inventory_hostname][item|basename] is defined 
>>
>>
>> If you want to combine variable with a string the syntax is 
>>
>> hostvars[inventory_hostname][myvar ~ 'my_string'] is defined 
>>
>>
>> -- 
>> Kai Stian Olstad 
>>
>>
>>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/adeedb80-4723-4319-a3a5-1e6d11218d0b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] rpm-python centos5 package package_facts

2019-03-08 Thread Adam E
hey Matt,  just to ensure i'm clear, after the rebuild do you just need to 
install the rpm-python26 rpm or does it create rebuilt versions of the yum 
and rpm distributions as well that all need to also be updated.

if it's only rpm-python then I may give your build a shot, but I tried a 
bunch of things and I assume that there are newer versions of rpm libraries 
needed as well which look to be what your build is doing ;-) .  That 
doesn't look like fun, pretty impressive though ;-)


On Friday, March 8, 2019 at 2:22:33 PM UTC-8, Matt Martz wrote:
>
> I did some experimenting with this about a year ago.  I have a repo that 
> has a playbook that can build the packages for EL5 using python2.6 from 
> EPEL.
>
> NOTE: I don't necessarily recommend this, it was an experiment to see if 
> it could be done
>
> WARNING: Proceed at your own risk ;)
>
> https://github.com/sivel/el5-python26-rpm
>
> The last release of Ansible to support EL5 natively was Ansible 2.3
>
> On Fri, Mar 8, 2019 at 4:16 PM S C Rigler > 
> wrote:
>
>> If you can install a newer python on the machines you should be able
>> to manage them by setting the inventory variable
>> "ansible_python_interpreter" for them to the path of the alternate
>> python interpreter.
>>
>> On Fri, Mar 8, 2019 at 2:25 PM Adam E > 
>> wrote:
>> >
>> > hey there, i'm trying to manage a bunch of centos5/rhel5 systems with 
>> ansible 2.7.5
>> >
>> > On the target host I am able to install python 2.6 from epel which is 
>> all good and ansible runs just fine for most stuff.   The issue is with 
>> anything related to packages (ie . package_facts and package).  They both 
>> rely on the "rpm" python library.
>> >
>> >
>> > Problem is, I can't figure out how to install this library on centos 
>> 5.   It seems the library is not available in epel
>> >
>> > I tried building from source but I then get the error below:
>> > # python26
>> > Python 2.6.8 (unknown, Nov  7 2012, 14:47:45)
>> > [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
>> > Type "help", "copyright", "credits" or "license" for more information.
>> > >>> import rpm
>> > rpm.py:15: UserWarning: The RPM Python bindings are not currently 
>> available via PyPI.
>> >
>> >
>> > Please install them with your distro package manager (typically called
>> > 'python2-rpm' or 'python3-rpm'), and ensure that any virtual 
>> environments
>> > needing the API are configured to be able to see the system site 
>> packages
>> > directory.
>> >
>> >
>> >   warnings.warn(warning_msg)
>> > >>>
>> >
>> >
>> > If I can't get this working, I guess my only options are to either just 
>> not manage packages on the legacy centos/rhel5 boxes or see about running 
>> an older version (multiple versions) of ansible within AWX.
>> >
>> > Just wondering if anyone has went through this already and can provide 
>> any tips.
>> >
>> > --
>> > 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 post to this group, send email to ansible...@googlegroups.com 
>> .
>> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/18a045ee-1f63-437b-a8c5-d10880e5cd50%40googlegroups.com
>> .
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> -- 
>> 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 post to this group, send email to ansible...@googlegroups.com 
>> .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/CAFbiokdgxMddo%3D-DP%2B5LVrGqyL_4PoHAddii%2BWH2cscEKhtbyA%40mail.gmail.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> -- 
> Matt Martz
> @sivel
> sivel.net
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/35f77629-8cd9-4407-9645-a901d5d315da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] rpm-python centos5 package package_facts

2019-03-08 Thread Adam E
hi Steve.  the python interpreter is not the issue.  I am using python 2.6 
without issues, the issue is the dependency on the rpm-python os package 
(python library).   I cannot find/install this for centos5.   the "rpm" 
library is not part of the standard python distro, it's an extra library.

On Friday, March 8, 2019 at 2:17:04 PM UTC-8, Steve R wrote:
>
> If you can install a newer python on the machines you should be able 
> to manage them by setting the inventory variable 
> "ansible_python_interpreter" for them to the path of the alternate 
> python interpreter. 
>
> On Fri, Mar 8, 2019 at 2:25 PM Adam E > 
> wrote: 
> > 
> > hey there, i'm trying to manage a bunch of centos5/rhel5 systems with 
> ansible 2.7.5 
> > 
> > On the target host I am able to install python 2.6 from epel which is 
> all good and ansible runs just fine for most stuff.   The issue is with 
> anything related to packages (ie . package_facts and package).  They both 
> rely on the "rpm" python library. 
> > 
> > 
> > Problem is, I can't figure out how to install this library on centos 5. 
>   It seems the library is not available in epel 
> > 
> > I tried building from source but I then get the error below: 
> > # python26 
> > Python 2.6.8 (unknown, Nov  7 2012, 14:47:45) 
> > [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2 
> > Type "help", "copyright", "credits" or "license" for more information. 
> > >>> import rpm 
> > rpm.py:15: UserWarning: The RPM Python bindings are not currently 
> available via PyPI. 
> > 
> > 
> > Please install them with your distro package manager (typically called 
> > 'python2-rpm' or 'python3-rpm'), and ensure that any virtual 
> environments 
> > needing the API are configured to be able to see the system site 
> packages 
> > directory. 
> > 
> > 
> >   warnings.warn(warning_msg) 
> > >>> 
> > 
> > 
> > If I can't get this working, I guess my only options are to either just 
> not manage packages on the legacy centos/rhel5 boxes or see about running 
> an older version (multiple versions) of ansible within AWX. 
> > 
> > Just wondering if anyone has went through this already and can provide 
> any tips. 
> > 
> > -- 
> > 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 post to this group, send email to ansible...@googlegroups.com 
> . 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/18a045ee-1f63-437b-a8c5-d10880e5cd50%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/dfcfab66-f579-4aea-8c82-58dd6dc8bfca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] rpm-python centos5 package package_facts

2019-03-08 Thread Adam E
hey there, i'm trying to manage a bunch of centos5/rhel5 systems with 
ansible 2.7.5

On the target host I am able to install python 2.6 from epel which is all 
good and ansible runs just fine for most stuff.   The issue is with 
anything related to packages (ie . package_facts and package).  They both 
rely on the "rpm" python library.


Problem is, I can't figure out how to install this library on centos 5.  
 It seems the library is not available in epel 


I tried building from source  but I 
then get the error below:
# python26
Python 2.6.8 (unknown, Nov  7 2012, 14:47:45)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import rpm
rpm.py:15: UserWarning: The RPM Python bindings are not currently available 
via PyPI.


Please install them with your distro package manager (typically called
'python2-rpm' or 'python3-rpm'), and ensure that any virtual environments
needing the API are configured to be able to see the system site packages
directory.


  warnings.warn(warning_msg)
>>>


If I can't get this working, I guess my only options are to either just not 
manage packages on the legacy centos/rhel5 boxes or see about running an 
older version (multiple versions) of ansible within AWX.

Just wondering if anyone has went through this already and can provide any 
tips.

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/18a045ee-1f63-437b-a8c5-d10880e5cd50%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Importing user variables from multiple variable sources

2019-03-02 Thread Adam E
I have a similar issue and solved it by this PR 
https://github.com/ansible/ansible/pull/51466 . if you want to use it, just 
grab the source code and add it to your local library directory until it's 
merged.  Also see this thread 
https://groups.google.com/forum/?utm_medium=email_source=footer#!msg/ansible-project/Ssnk6exNjNs/sCKlrOp_FQAJ

With the approach above, the code would merge together all lists that match a 
pattern, this way you can defined as many "users" variables as you want as long 
as they are unique and start with say "users_"

If you don't want to copy the library or wait for the PR, then you could also 
just merge a set of predefined lists.

ie..  
with_items: "{{ users_host|default([]) + users_group_l1|default([]) + 
users_group_l2|default([[) }}"

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a46f8eae-d2db-4251-96fd-f4f180d2b23b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] skip_unreachable ?

2019-02-27 Thread Adam E
I'm thinking about going down this road, if anyone has any better ideas, 
please share.  it seems as though it will work fine, just not sure if there 
is a better/simpler/more appropriate solution.

---

- name: "get down hosts"
  hosts: localhost

  tasks:

# TODO: update to call a dynamic script/action plugin to populate
#   with down hosts to be excluded
- name: add down host to group
  add_host:
hostname: '{{ item }}'
groupname: "unreachable_hosts"
  with_items:
- "host_unreachable"

- name: "unreachable test"
  hosts: "*:!unreachable_hosts"
  become: no

  tasks:

  - name: "success1"
copy:
  content: "my stuff"
  dest: /tmp/file.success1


On Wednesday, February 27, 2019 at 2:41:31 PM UTC-8, Adam E wrote:
>
> hi Brian, I was wondering if there is anything else you can suggest to 
> me.   I want to report a successful ansible run when the only thing that 
> failed were unreachable hosts so that it returns success back to AWX.
>
> Is there a callback plugin or some local customization that I can write in 
> the meantime and then contribute back to Ansible core?
>
> Or perhaps some sort of preprocessor that runs through the inventory and 
> removes unreachable/down hosts?
>
> I am interested in two things:
> 1. any type of quick workaround.   I tried the suggestion you mentioned 
> with regards to the meta_clear_host_errors, but this didn't work.  I posted 
> the output below.  Even if it did work, I would be concerned that it would 
> clear other errors other than unreachable.
> 2. What is the correct long term solution (enhancement to ansible) to this 
> problem, if you agree this would be useful and can provide some guidance of 
> a solution you support and I can also work on a PR to add to the the core 
> if it's not too complex.  I think this would be useful.
>
>
> $ ansible-playbook  -i inventories.unreachable/ unreachable2.yml ; echo 
> "return 
> code from run is: $?"
>
>
> PLAY [unreachable test] 
>
>
> TASK [Gathering Facts] ***
> ok: [host_online]
> fatal: [host_unreachable]: UNREACHABLE! => {"changed": false, "msg": "Failed 
> to connect to the host via ssh: ssh: connect to host 10.20.3.21 port 22: 
> Connection timed out\r\n", "unreachable": true}
>
>
> TASK [success1] *
> changed: [host_online]
>
>
> TASK [success1] **
> fatal: [host_unreachable]: UNREACHABLE! => {"changed": false, "msg": "Failed 
> to connect to the host via ssh: ssh: connect to host 10.20.3.21 port 22: 
> Connection timed out\r\n", "unreachable": true}
>  to retry, use: --limit @/homenfs/aedwards/unreachable2.retry
>
>
> PLAY RECAP **
> host_online: ok=2changed=1unreachable=0failed=
> 0
> host_unreachable   : ok=0changed=0unreachable=2failed=
> 0
>
>
> return code from run is: 4
>
>
> playbook:
> $ cat unreachable2.
> $ cat unreachable2.yml
> ---
>
>
> - name: "unreachable test"
>   hosts: "*"
>   become: no
>
>
>   tasks:
>
>
>   - name: "success1"
> copy:
>   content: "my stuff"
>   dest: /tmp/file.success1
>
>
>   - meta: clear_host_errors
>
>
>
> On Wednesday, January 16, 2019 at 3:21:24 PM UTC-8, Brian Coca wrote:
>>
>> So what you are asking would be the 'default' way ansible operates, it 
>> removes 'unreachable' hosts from the rest of the play and then 
>> continues with the rest of the hosts. 
>> > - any future tasks in the play against that host will not be run (no 
>> point as they will all fail as host unreachable). 
>>   this is the default 
>> > - the playbook will continue run all tasks against the other hosts that 
>> are reachable 
>>also the default 
>> > - the playbook run will report success (return code = 0) 
>>   this is not the default, but you can have a `meta: 
>> clear_host_errors` as your last task .. but this might be too big of a 
>> hammer. 
>>
>> There are some cases in which the above is not true, for example, 
>> using serial, if all hosts in a 'serial batch' fail (unreachable 
>> counts) then the whole play fails, you also have max_fail_percentage 
>> to manage how many failures you tolerate. 
>>
>>
>> -- 
>> Brian Coca 
>>
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/533c83f4-8d1f-4c3a-b791-7501069248e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] skip_unreachable ?

2019-02-27 Thread Adam E
hi Brian, I was wondering if there is anything else you can suggest to me.  
 I want to report a successful ansible run when the only thing that failed 
were unreachable hosts so that it returns success back to AWX.

Is there a callback plugin or some local customization that I can write in 
the meantime and then contribute back to Ansible core?

Or perhaps some sort of preprocessor that runs through the inventory and 
removes unreachable/down hosts?

I am interested in two things:
1. any type of quick workaround.   I tried the suggestion you mentioned 
with regards to the meta_clear_host_errors, but this didn't work.  I posted 
the output below.  Even if it did work, I would be concerned that it would 
clear other errors other than unreachable.
2. What is the correct long term solution (enhancement to ansible) to this 
problem, if you agree this would be useful and can provide some guidance of 
a solution you support and I can also work on a PR to add to the the core 
if it's not too complex.  I think this would be useful.


$ ansible-playbook  -i inventories.unreachable/ unreachable2.yml ; echo "return 
code from run is: $?"


PLAY [unreachable test] 


TASK [Gathering Facts] ***
ok: [host_online]
fatal: [host_unreachable]: UNREACHABLE! => {"changed": false, "msg": "Failed 
to connect to the host via ssh: ssh: connect to host 10.20.3.21 port 22: 
Connection timed out\r\n", "unreachable": true}


TASK [success1] *
changed: [host_online]


TASK [success1] **
fatal: [host_unreachable]: UNREACHABLE! => {"changed": false, "msg": "Failed 
to connect to the host via ssh: ssh: connect to host 10.20.3.21 port 22: 
Connection timed out\r\n", "unreachable": true}
 to retry, use: --limit @/homenfs/aedwards/unreachable2.retry


PLAY RECAP **
host_online: ok=2changed=1unreachable=0failed=0
host_unreachable   : ok=0changed=0unreachable=2failed=0


return code from run is: 4


playbook:
$ cat unreachable2.
$ cat unreachable2.yml
---


- name: "unreachable test"
  hosts: "*"
  become: no


  tasks:


  - name: "success1"
copy:
  content: "my stuff"
  dest: /tmp/file.success1


  - meta: clear_host_errors



On Wednesday, January 16, 2019 at 3:21:24 PM UTC-8, Brian Coca wrote:
>
> So what you are asking would be the 'default' way ansible operates, it 
> removes 'unreachable' hosts from the rest of the play and then 
> continues with the rest of the hosts. 
> > - any future tasks in the play against that host will not be run (no 
> point as they will all fail as host unreachable). 
>   this is the default 
> > - the playbook will continue run all tasks against the other hosts that 
> are reachable 
>also the default 
> > - the playbook run will report success (return code = 0) 
>   this is not the default, but you can have a `meta: 
> clear_host_errors` as your last task .. but this might be too big of a 
> hammer. 
>
> There are some cases in which the above is not true, for example, 
> using serial, if all hosts in a 'serial batch' fail (unreachable 
> counts) then the whole play fails, you also have max_fail_percentage 
> to manage how many failures you tolerate. 
>
>
> -- 
> Brian Coca 
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/71feebc9-5050-4f7c-8f8f-b14eae9365c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] merging specific group_vars without changing global behavior

2019-01-29 Thread Adam E
In my environment i have a group_vars structure something like the 
following:
[global:children]
datacenter1


[datacenter1:children]
network_zone1
network_zone2


[network_zone1]
server1


[network_zone2]
server2


so using a simple case where I want to add entries to /etc/hosts (although 
there are other use cases, this just seemed the simplest to demonstrate)
I want to be able to set group_vars within each group that get 
merged/appended together for processing by my role.  However 
since the default ansible behavior is not to merge and I don't really want 
to change the default.
therefore I was thinking about doing something like this:

[global:vars]
linux_hosts_entries_global:
  - { ip: 123.124.125.125, names: [backup_server]} 


[datacenter1:vars]
linux_hosts_entries_dc1:
  - { ip: 123.124.125.126, names: [dc1_server]} 


[network_zone1:vars]
linux_hosts_entries_z1:
  - { ip: 123.124.125.125, names: [z1_server]}


Then I could do something like below to loop through the variables to get a 
merged list.   
- name: "debug2"
  debug:
msg: "value is: {{ lookup('vars', item) }} "
  loop: "{{ hostvars[inventory_hostname] | select('match', 
'^linux_hosts_entries') |list  }}"


or in the case of a template, you could do something like this:
{% set linux_hosts_merged_entries =  hostvars[inventory_hostname] | select(
'match', '^linux_hosts_entries') |list %}
{% for groupvar_name in linux_hosts_merged_entries %}
  {% set host_entries = lookup('vars', groupvar_name) %}
  {% for host_entry in host_entries %}
{{ host_entry.ip }} {{ host_entry.names | join(' ') }}
  {% endfor %}
{% endfor %}


I was wondering how others are handling similar use cases?  is there a 
simpler solution?
This strategy seems to work quite well.

I am aware of combine/union filters, however these require that you know 
the names of the variables ahead of time.  I like that in this model I can 
add additional variables later without affecting the existing setup.

I also created a PR to simplify further by adding regex support 
 to the lookup vars plugin.

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e04a6e1f-4edc-4e0c-9660-26ff8c8ebd8f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: need ansible to wait for a springboot acutuator heathcheck to show up

2019-01-25 Thread Adam E
something like this should work

- name: "wait for status"
  shell: bash -c 'curl -s http://{{  server_name }}:
*8093/service/actuator/health* |egrep "^status"'
  register: cmd_res
  retries: "60"
  delay: 1
  until: cmd_res.stdout.find('"status": "UP") != -1

On Friday, January 25, 2019 at 5:25:16 AM UTC-8, John Simmons wrote:
>
> Hi Hope you can help me again
>
> I need to wait for a spring application to start before moving on in my 
> playbook.
> when the microservice starts it runs flyway script that can take a long 
> time to run before the service actually starts working.
>
> would the uri module be able to check a specific url for specific text?
>
> so if i wanted to check: *localhost:8093/service/actuator/health*
>
> for this text:
>
>   "status" : "UP"
>
> and not just look for a 200 message?
>
> is this possible? if so how
>
> Many thanks in advance
>
> John
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/18727b34-a135-40f5-b3d8-9f8cadeffb6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Options for filtering hosts

2019-01-23 Thread Adam E
If you happen to be using awx, you can enable fact caching and then create a 
dynamic inventory which can be based on search results including facts values

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/10f4a59d-6c8f-4419-931b-e50e789361f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] skip_unreachable ?

2019-01-16 Thread Adam E
thanks for the reply Brian.  Yes, it sounds like clear_host_errors i think 
will be too big of a hammer, I just want to ignore unreachable.

I'll have to figure something else out then, have a couple other scenarios 
in mind anyways, gonna also look at 
 something like  https://github.com/openstack/ara to have better 
logging/reporting on playbook runs so I can more easily find the failed 
hosts and rerun.

ultimately just looking for a nice clean way to monitor and re-run failed 
executions, as well as easily distinguish things like connection failures 
vs actual failures where you know that running it again when the connection 
is up will work.   I don't find AWX gives me a good enough view into this 
and am looking for a better overall strategy.

On Wednesday, January 16, 2019 at 3:21:24 PM UTC-8, Brian Coca wrote:
>
> So what you are asking would be the 'default' way ansible operates, it 
> removes 'unreachable' hosts from the rest of the play and then 
> continues with the rest of the hosts. 
> > - any future tasks in the play against that host will not be run (no 
> point as they will all fail as host unreachable). 
>   this is the default 
> > - the playbook will continue run all tasks against the other hosts that 
> are reachable 
>also the default 
> > - the playbook run will report success (return code = 0) 
>   this is not the default, but you can have a `meta: 
> clear_host_errors` as your last task .. but this might be too big of a 
> hammer. 
>
> There are some cases in which the above is not true, for example, 
> using serial, if all hosts in a 'serial batch' fail (unreachable 
> counts) then the whole play fails, you also have max_fail_percentage 
> to manage how many failures you tolerate. 
>
>
> -- 
> Brian Coca 
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/842756e0-0741-4af3-8f74-cf75cb0a8464%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] skip_unreachable ?

2019-01-15 Thread Adam E
Hi there.

My scenario is that I have a hundreds of locations on various different 
networks that I want to run some plays against.   In almost all 
circumstances I will have 2-3% of these sites that I cannot connect to due 
to network related issues.I don't want to create exceptions/errors in 
AWX for these sites that just happen to be offline while we are running the 
play, they'll get picked up again next time.

The behaviour I would like is that when a host is deemed as unreachable, 
- any future tasks in the play against that host will not be run (no point 
as they will all fail as host unreachable).  
- the playbook will continue run all tasks against the other hosts that are 
reachable
- the playbook run will report success (return code = 0)

I was thinking of using the ignore_unreachable flag which seems to mostly 
do what I want, however based on the documentation and the comments in a 
issue  I just created it 
seems as though the ignore_unreachable flag is not aligned with my goals, 
the opposite in fact.

Is there another flag/option that might give me something closer to what I 
am looking for?  


-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a29334e2-f3a7-43ef-a3eb-81eec93a10a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.