Thank you – this worked and it’s a lot cleaner then the way I was doing it - I knew about the yum module but because it did not have any return values I was afraid that it just kicked off the update and moved on - I'm glad that's not the case
On Friday, March 22, 2019 at 12:32:36 AM UTC-7, Sudheer Satyanarayana wrote: > > > On 22/03/19 5:34 AM, [email protected] <javascript:> wrote: > > The following playbook worked for me, but I just started with Ansible and > I'm wondering if I went about this wrong? I feel like I may have missed an > easier way to say: do something only after a package has finished > installing ... > tasks: - name: Install python3 with a specific command and register stdout > to a var command: sudo yum -y install python3 python3-pip register: varname > - name: Create a directory only after python3 has been installed file: > path: /home/ec2-user/newdirectory state: directory when: > varname.stdout.find("Complete!") != -1 > > > > > > > > > > Avoid using the command module when there are specific Ansible modules > available for the task. To install packages via yum, there's the yum module. > > https://docs.ansible.com/ansible/latest/modules/yum_module.html > > And use `become` to escalate privilege. > > Your playbook can be rewritten like : > > tasks: > - name: Install python3 > yum: > name: > - python3 > - python3-pip > become: true > > - name: Create a directory > file: > path: /home/ec2-user/newdirectory > state: directory > > The first task in the playbook will ensure that the packages are installed > via yum. If there are any problems, Ansible will report it. The second > task, ie, creating directory will run only if the first task succeeds. In > general, playbook execution stops if any task fails. There is no need to > check for the status of the first task. > > - > > Sudheer S > > On Thursday, March 21, 2019 at 2:24:58 PM UTC-7, [email protected] wrote: >> >> Hello, >> >> I have two tasks in a playbook. The first task installs software with the >> command module. The second creates a file. I don’t want the second task to >> run until the software has finished installing. I’m pretty sure I need to >> use “when”, but I’m not sure what to evaluate to determine that the >> software has finished installing. >> >> I’m thinking that I could use the stdout of this yum command? The last >> line output to the screen is “Complete!” would it be possible to base the >> “when” on the existence of that text string in stdout? >> something like: >> >> - name: Install python3 with a specific command and register stdout to a >> var >> command: sudo yum -y install python3 python3-pip >> register: stdout >> >> - name: Create a directory after python3 has been installed >> >> file: >> >> path: /home/newdirectory >> >> state: directory >> >> when: [a line of text in stdout] == "Complete!" >> >> >> Does this logic even make sense? I assumed that "register" would put all >> of stdout into an array of lines of strings, but I don't if that's how it >> works or not or how to search stdout for the string "Complete!"? >> >> Thanks much for any help >> > -- > 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 [email protected] <javascript:>. > To post to this group, send email to [email protected] > <javascript:>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/cdc8e599-deb7-4c7c-b94f-a2494feef196%40googlegroups.com > > <https://groups.google.com/d/msgid/ansible-project/cdc8e599-deb7-4c7c-b94f-a2494feef196%40googlegroups.com?utm_medium=email&utm_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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f1069ab5-d106-4ca5-b5d0-8e93b7e451dc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
