[ansible-project] Re: Find module results not returning as expected

2018-04-07 Thread flowerysong
On Saturday, April 7, 2018 at 8:50:44 AM UTC-4, Gabriel Forster wrote:
>
> Using the find module to find unknown files in a given directory and 
> register the results as a variable to be looped through later on. The debug 
> of the registered var shows a full on array of all kinds of attributes 
> about the files (way more than I want) - except the file name! It does show 
> the file name in the files.path, which I should be able to filter with 
> basename, but that doesn't work either. This either should be much more 
> straightforward, or my understanding of this is way off.
>
> Question: How do I store unknown file names in a dir as a list that I can 
> loop through in a subsequent task?
>
>
> My current play (I've tried a few different iterations - and the echo is 
> just an example, would like to do other things like use the script module 
> and such):
>
>  ---
>  - hosts: localhost
>tasks:
>  - name: Check the files
>find:
>  paths: /home/gforster/projects/scripts
>register: files_found
>  
>  - name: echo files
>command: "echo {{ item.path | basename }}"
>loop: "{{ files_found.files }}"
>
>
>
>
> Expected Results:
>
> TASK [echo files] 
> *
> changed: [localhost] => {
> "msg": "some_filesname"
> }
>

If you want to output a message use the debug module, not "command: echo".

- name: echo files
  debug:
msg: "{{ item.path | basename }}"
  loop: "{{ files_found.files }}"


TASK [echo files] 
**
ok: [localhost] => (item=None) => {
"msg": "vault.zip"
}

-- 
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/dced9739-702b-43ec-8082-993e55dc7fa1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Find module results not returning as expected

2018-04-07 Thread Gabriel Forster
Using the find module to find unknown files in a given directory and 
register the results as a variable to be looped through later on. The debug 
of the registered var shows a full on array of all kinds of attributes 
about the files (way more than I want) - except the file name! It does show 
the file name in the files.path, which I should be able to filter with 
basename, but that doesn't work either. This either should be much more 
straightforward, or my understanding of this is way off.

Question: How do I store unknown file names in a dir as a list that I can 
loop through in a subsequent task?


My current play (I've tried a few different iterations - and the echo is 
just an example, would like to do other things like use the script module 
and such):

 ---
 - hosts: localhost
   tasks:
 - name: Check the files
   find:
 paths: /home/gforster/projects/scripts
   register: files_found
 
 - name: echo files
   command: "echo {{ item.path | basename }}"
   loop: "{{ files_found.files }}"


Expected Results:

TASK [echo files] 
*
changed: [localhost] => {
"msg": "some_filesname"
}





Actual Results:
TASK [echo files] 
*
changed: [localhost] => (item={u'uid': 1000, u'woth': True, u'mtime': 
1522857501.1654217, u'inode': 20547673299942532, u'isgid': False, u'size': 
359, u'roth': True, u'isuid': False, u'isreg': True, u'pw_name': u'gforster'
, u'gid': 1000, u'ischr': False, u'wusr': True, u'xoth': False, u'rusr': 
True, u'nlink': 1, u'issock': False, u'rgrp': True, u'gr_name': u'gforster', 
u'path': u'/home/gforster/projects/scripts/101_names', u'xusr': False, u
'atime': 1522857501.1649039, u'isdir': False, u'ctime': 1522857501.1654217, 
u'wgrp': True, u'xgrp': False, u'dev': 2, u'isblk': False, u'isfifo': False, 
u'mode': u'0666', u'islnk': False})
changed: [localhost] => (item={u'uid': 1000, u'woth': True, u'mtime': 
1522857463.1172974, u'inode': 9570149208257507, u'isgid': False, u'size': 
1261, u'roth': True, u'isuid': False, u'isreg': True, u'pw_name': u
'gforster', u'gid': 1000, u'ischr': False, u'wusr': True, u'xoth': False, u
'rusr': True, u'nlink': 1, u'issock': False, u'rgrp': True, u'gr_name': u
'gforster', u'path': u'/home/gforster/projects/scripts/101_to_masterfile', u
'xusr': False, u'atime': 1522857457.6757936, u'isdir': False, u'ctime': 
1522857463.1829827, u'wgrp': True, u'xgrp': False, u'dev': 2, u'isblk': 
False, u'isfifo': False, u'mode': u'0666', u'islnk': False})





-- 
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/ebfee943-d269-4b83-bb92-fc55383becdc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] lxc connection plugin - sudo first?

2018-04-07 Thread Richard Hector
Hi all,

I'm trying to use the lxc connection plugin, but it says that my
container isn't running. Presumably that's because ansible isn't running
as root. Is there a way to tell it to sudo before connecting?

I'm aware of course of how to sudo _afterwards_, ie on the target
system, to do anything useful, but I need to connect first.

I need to do this to set up the container for ssh, so I can continue
with that later.

Thanks,

Richard

-- 
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/a08bce9b-f454-12d8-7c44-cb40a4ccbebe%40walnut.gen.nz.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] [SOLVED] Re: How to load variables for a tagged role?

2018-04-07 Thread Karl Auer
Possibly bad form to reply to one's own query, but I think I worked it out.

Rather than tag every task inside the role, I split the big role up into 
four. I removed ALL the tagging from inside the roles, and set up this 
little playbook:

---

- hosts: localhost
  connection: local
  gather_facts: false

  pre_tasks:
 - include_vars: blah_envs/{{env}}.yaml
   tags: always
 - include_vars: blah_envs/common.yaml
   tags: always

  roles:
 - { role: blah_server, tags: [ server ] }
 - { role: blah_portal, tags: [ portal ] }
 - { role: blah_alb,tags: [ alb] }
 - { role: blah_asg,tags: [ asg] }

... and now it all works as desired. The real breakthrough was figuring out 
that include_vars is a task :-)

Regards, K.

On Saturday, April 7, 2018 at 4:07:20 PM UTC+10, Karl Auer wrote:
>
> I have a large role, which I will break down into separate roles 
> eventually.
>
> For the moment, I am trying to use tags to selectively run bits of it, 
> tagged e.g. "server", "portal" etc.
>
> The role is called from this playbook:
>
> ---
>
> - hosts: localhost
>   connection: local
>   gather_facts: false
>
>   pre_tasks:
>  - include_vars: blah_envs/{{env}}.yaml
>  - include_vars: blah_envs/common.yaml
>
>   roles:
>  - blah
>
> The whole thing works fine if I just run that playbook, specifying a 
> suitable value for "env".
>
> However, if I also specify a tag on the command line e.g. "--tags server", 
> Ansible gives me an error message:
>
>The task includes an option with an undefined variable
>
> ... and mentions a variable that is defined in one of the var files. It 
> seems that those pre-tasks are not happening, a theory that is borne out by 
> the fact that I usually see a status output listing the variables that have 
> just been loaded, but I do not see that output when I specify a tag.
>
> How can I get those variables to load and be available to the tagged tasks 
> I am running?
>
> If I put "tags: always" in the pre-tasks stanza, it appears to set the tag 
> on the whole playbook, as everything runs, it doesn't just always load the 
> vars.
>
> Regards, K.
>
>

-- 
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/2e8dc133-8043-42d0-bb62-03a702360d7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] How to load variables for a tagged role?

2018-04-07 Thread Karl Auer
I have a large role, which I will break down into separate roles eventually.

For the moment, I am trying to use tags to selectively run bits of it, 
tagged e.g. "server", "portal" etc.

The role is called from this playbook:

---

- hosts: localhost
  connection: local
  gather_facts: false

  pre_tasks:
 - include_vars: blah_envs/{{env}}.yaml
 - include_vars: blah_envs/common.yaml

  roles:
 - blah

The whole thing works fine if I just run that playbook, specifying a 
suitable value for "env".

However, if I also specify a tag on the command line e.g. "--tags server", 
Ansible gives me an error message:

   The task includes an option with an undefined variable

... and mentions a variable that is defined in one of the var files. It 
seems that those pre-tasks are not happening, a theory that is borne out by 
the fact that I usually see a status output listing the variables that have 
just been loaded, but I do not see that output when I specify a tag.

How can I get those variables to load and be available to the tagged tasks 
I am running?

If I put "tags: always" in the pre-tasks stanza, it appears to set the tag 
on the whole playbook, as everything runs, it doesn't just always load the 
vars.

Regards, K.

-- 
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/c369e1e6-7dce-4110-b580-55163a3d8a99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.